题解 | #确定最佳顾客的另一种方式(二)#
确定最佳顾客的另一种方式(二)
http://www.nowcoder.com/practice/b5766f970ae64ac7944f37f5b47107aa
- SELECT 后面跟着聚合函数字段的话,后面其他的字段都得是分组条件。 例如有聚合函数SUM,按照...分组,这一组的总数是...
SELECT cust_name, temp.total_price
FROM Customers c
JOIN
(SELECT cust_id, SUM(item_price*quantity) AS total_price
FROM OrderItems ot
LEFT JOIN Orders o ON ot.order_num = o.order_num
GROUP BY cust_id) AS temp
ON c.cust_id = temp.cust_id
WHERE temp.total_price >= 1000
ORDER BY temp.total_price ASC