老师,这里问几个SQL习题的问题:
- Q2: select country, count(posts) * 1.0 / count(user_id) as avg_posts, 看from的subquery里面应该是先计算出每个user每个date的总post数,那这边应该是sum(posts)还是count(posts)?
- Q19: subquery是
from(
select post_id as id, content_type, count(*) as num_comments
from ()t1 left join ()t2 on …
group by post_id) t3
这里面group by 后面除了post_id, 需不需要加上content_type? 不加postgresql会报错吗? - Q30: select… coalesce(sum(t1.price) * 1.0 / sum(t2.spend), 0) as ROI, 这里是不是应该 t2.price, t1.spend?