题解 | 请写出计算粉丝ctr的sql语句
该题表达不清晰,没有做好解释,题目实际考的是“某条内容只被该内容创作者的粉丝所产生的行为”,而c表的用户行为表中会有不是该内容创作者粉丝的曝光阅读行为,限制作者与粉丝关系的join逻辑可以使用in的方式写
select
sum(read_num)/sum(show_num) as fans_ctr
from
(
select
c.content_id
,c.fans_id
,b.author_id
,sum(show_num) as show_num
,sum(read_num) as read_num
from c
inner join b
on c.content_id=b.content_id
group by c.content_id
,c.fans_id
,b.author_id
) t1
inner join a
on t1.author_id=a.author_id and t1.fans_id=a.fans_id