第二题暴力解 select uid
from user_info
where gender='女' and age<='25'
and uid in
(select uid from user_video
where date>='20190801' and date<='20190807' and tag=='美食'
group by uid
having count(uid)>10)
and uid in
(select uid from user_video
where date=='20190808' and tag=='美食'
group by uid
having count(uid)<3) 第三题 select distinct tag, max(cnt) over (partition by tag)-min(cnt) over (partition by tag)
from
(select tag, uid, count(uid) cnt
from user_video
group by tag, uid) 第一题求大佬 突然发现个问题,他所有的字段都是varchar的……包括年龄这种数字
我后两题通过了,但是我没记下来答案,第一题总觉得有问题,就放弃了,我记得第二题我思路比较笨,先求的看超过10次是uid表,再inner join 小于3次的uid表,第三题select tag,max(num)-min(num) from (select tag,count(vid) as num from 表 group by tag,uid) group by tag; 是我乱试出来的
2,3跑通了,第一题怎么也调不对,求大神指点,下面是1,2题,第三题忘了粘过来了。。。 --1
select b.channel_type as '渠道类型',sum(a.cishu)/count(a.uid) as '人均观看次数',
round(
((sum(case when date='20190711' then a.cishu else 0 end) / count(case when date='20190711' then a.uid else null end))
-(sum(case when date='20190710' then a.cishu else 0 end) / count(case when date='20190710' then a.uid else null end))),
4) as '涨幅'
from
(
select date,uid,count(*) as cishu
from user_video
where date in ('20190710','20190711')
group by 1,2
)a
left join
(
select uid,channel_type
from new_user_info
)b on a.uid=b.uid
group by 1
--2
select c.uid
from
(
select a.uid as uid,sum(case when dt>='20190801' and dt<='20190807' then b.cishu else 0 end) as seven,
sum(case when dt='20190808' then b.cishu else 0 end) as eight
from
(select uid
from user_info
where gender='女' and age<='25')a
left join
(select uid,date as dt,count(*) as cishu
from user_video
where tag='美食'
and date>='20190801' and date<='20190808'
group by 1,2)b on a.uid=b.uid
group by 1
)c
where c.seven>10 and c.eight<3