之前在编写oracle的sql语句时遇到这个问题,这里做个记录
问题描述:ORA-00937: 不是单组分组函数
问题原因:select语句中又在查询某一列的值,其中还有聚合函数
原先本人编写SQL是这样的
--查找配送单的收货配送点、送货配送点、配送包数量-- select R_DELIVEPOINT_ID,S_DELIVEPOINT_ID,SUM(PACK_NUM) PACK_NUM from TMS_DELIVERY;
其中,用到聚合函数SUM(),执行时导致这个问题
如果要解决这个问题,SQL语法可以改成这样:
1)取消聚合函数
--查找配送单的收货配送点、送货配送点、配送包数量-- select R_DELIVEPOINT_ID,S_DELIVEPOINT_ID,PACK_NUM from TMS_DELIVERY;
2)支持聚合函数(添加group by)
--查找配送单的收货配送点、送货配送点、配送包数量-- select R_DELIVEPOINT_ID,S_DELIVEPOINT_ID,SUM(PACK_NUM) PACK_NUM from TMS_DELIVERY group by R_DELIVEPOINT_ID,S_DELIVEPOINT_ID;
参考网址:
https://blog.csdn.net/weixin_43705313/article/details/99290635