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;