题解 | #计算总和#

计算总和

http://www.nowcoder.com/practice/d8a624021183454586da94d280cc8046

SELECT 
    order_num,
    SUM(item_price * quantity) total_price
FROM
    OrderItems
GROUP BY
    order_num
HAVING
    total_price >= 1000
ORDER BY
    order_num;

全部评论
请问一下,为何我将item_price * 移到sum函数外部就会报错运行不了,就像下面这个样子 SELECT order_num, item_price *SUM(quantity) total_price FROM OrderItems GROUP BY order_num HAVING total_price >= 1000 ORDER BY order_num; 报错如下 SQL_ERROR_INFO: "Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'OrderItems.item_price' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by"
2 回复 分享
发布于 2022-03-11 11:02
小白有点想不懂,请教一下,为什么要用sum,不能直接item_price * quantity,然后group by bu不是会分组后把item_price * quantity汇总吗?
点赞 回复 分享
发布于 2022-09-07 11:50 北京

相关推荐

牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
AFBUFYGRFHJLP:直接去美帝试试看全奖phd吧
点赞 评论 收藏
分享
评论
11
5
分享
牛客网
牛客企业服务