题解 | #确定最佳顾客的另一种方式(二)#

确定最佳顾客的另一种方式(二)

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
全部评论

相关推荐

脾气小祖宗:这简历摸到都得狠狠地消毒液洗手😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务