题解 | #计算总和#

计算总和

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

相关推荐

面向对象的火龙果很爱...:去吃一顿炸鸡就走
点赞 评论 收藏
分享
06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
07-03 16:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
11
5
分享

创作者周榜

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