题解 | SQLW17 统计商家不同会员每日访问人次及访问人数
WITH t1 AS ( SELECT a.user_id, b.vip FROM visit_tb a LEFT JOIN uservip_tb b ON a.user_id = b.user_id ), t2 AS ( SELECT vip, count(user_id) AS visit_nums, count(DISTINCT user_id) AS visit_users FROM t1 GROUP BY vip ORDER BY visit_nums DESC )SELECT * FROM t2; # 这道题关键在于是否去重计数!