官方题解 | #小破站鬼畜区的用户里有多少用户看过汽车区#

小破站鬼畜区的用户里有多少用户看过汽车区

http://www.nowcoder.com/practice/5b7d2f4a276c4d4cb2e0a7338f7e7d96

step1:使用vidio_id相等的条件,将user_view_tb左连接vidio_info_tb得到两个新表t1和t2;

step2: 将t1和t2按照user_id相等,并且t1中的视频类型为鬼畜,t2中的视频内容为汽车进行连接;

step3: t2中user_id不为空的个数即为鬼畜区的用户里看过汽车的个数。

SELECT count(distinct t2.user_id) as num

FROM

(SELECT user_id, view_date, video_name, video_type

from user_view_tb a

left join video_info_tb b

on a.video_id=b.video_id

)t1

left join

(SELECT user_id, view_date, video_name, video_type

from user_view_tb a

left join video_info_tb b

on a.video_id=b.video_id

)t2

on t1.user_id=t2.user_id and t1.video_type='鬼畜' and t2.video_type='汽车'

where t2.user_id is not NULL;

全部评论

相关推荐

哞客37422655...:你猜为什么福利这么好还得一直追着你问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务