WITH temp AS(
SELECT b.user_id,b.point,COALESCE(a.total_cost,0) AS total_cost
FROM(
SELECT user_id,sum(order_price) as total_cost
FROM order_tb
WHERE order_price > 100
GROUP BY user_id
) AS a
JOIN uservip_tb AS b ON a.user_id = b.user_id
)
SELECT user_id,point + total_cost as 'point'
FROM temp
ORDER BY point DESC
感觉写的有点麻烦

京公网安备 11010502036488号