题解 | SQLW23 更新用户积分信息?
WITH t1 AS ( SELECT user_id, SUM(order_price) AS order_price FROM order_tb WHERE order_price > 100 GROUP BY user_id ), t2 AS ( SELECT t1.user_id, b.point + order_price AS point FROM t1 LEFT JOIN uservip_tb b ON t1.user_id = b.user_id ORDER BY point DESC )SELECT * FROM t2; # 关键在于分组求和先计算。