题解 | #计算总和#

计算总和

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 北京

相关推荐

10-09 22:05
666 C++
找到工作就狠狠玩CSGO:报联合国演讲,报电子烟设计与制造
点赞 评论 收藏
分享
11-27 17:08
已编辑
牛客_产品运营部_私域运营
腾讯 普通offer 24k~26k * 15,年包在36w~39w左右。
点赞 评论 收藏
分享
评论
11
5
分享
牛客网
牛客企业服务