题解 | 统计各等级会员用户下订单总额
统计各等级会员用户下订单总额
https://www.nowcoder.com/practice/48dd35a3dd8c4e1494db36b097a03300
select
vip,
COALESCE(SUM(order_price), 0) as order_total
from
order_tb t1
right join uservip_tb t2 on t1.user_id = t2.user_id
group by
t2.vip
order by
order_total desc
# 此表采用的是右连接,右连接才会有空值
有没有人犯和我一样的错误, order_tb t1
left join uservip_tb t2 on t1.user_id = t2.user_id 时候,因为大表左连接小表,此时合并表是没有null值的,所以此时查询出的记录没有0,这个题一定是大表右连接小表,或者是小表左连接大表才可以

