oracle sql语句 group by 不能用的问题

selectt2.areaaswe,t2.clientyear,t2.clientmonth,t2.goodsno,t2.goodsname,t2.targetamoun... select t2.area as we,t2.clientyear,t2.clientmonth,t2.goodsno,t2.goodsname,t2.targetamount,sd.quantityfrom drp_salesorder_detail sd left join(select ds.ordersno,extract(year from ds.orderdate) clientyear,extract(month from ds.orderdate) clientmonth,ds.purchasesno,t1.goodsno,t1.area,t1.targetamount,t1.goodsnamefrom DRP_SALESORDER ds left join(select dc.area,dcs.clientyear,dcs.clientmonth,dcs.goodsno,dcs.clientno,dcs.targetamount,dcs.goodsnamefrom drp_client dc left join drp_client_salestarget dcson dcs.clientno = dc.clientno) t1 on ds.purchasesno = t1.clientno) t2 on sd.goodsno = t2.goodsno

这个是可以运行的,如图

但是我想把 sd.quantity求和 就不行了..

语句如下 只修改了 sum(sd.quantity) 和后面的group by语句
select t2.area as we,t2.clientyear,t2.clientmonth,t2.goodsno,t2.goodsname,t2.targetamount,sum(sd.quantity)from drp_salesorder_detail sd left join(select ds.ordersno,extract(year from ds.orderdate) clientyear,extract(month from ds.orderdate) clientmonth,ds.purchasesno,t1.goodsno,t1.area,t1.targetamount,t1.goodsnamefrom DRP_SALESORDER ds left join(select dc.area,dcs.clientyear,dcs.clientmonth,dcs.goodsno,dcs.clientno,dcs.targetamount,dcs.goodsnamefrom drp_client dc left join drp_client_salestarget dcson dcs.clientno = dc.clientno) t1 on ds.purchasesno = t1.clientno) t2 on sd.goodsno = t2.goodsnogroup by we

group by 后面跟什么都不可以!!求高手
展开
 我来答
tj_angela
2014-04-03 · TA获得超过7530个赞
知道大有可为答主
回答量:6797
采纳率:75%
帮助的人:2573万
展开全部
select t2.area as we,t2.clientyear,t2.clientmonth,t2.goodsno,t2.goodsname,t2.targetamount,sum(sd.quantity)
from drp_salesorder_detail sd left join
(select ds.ordersno,extract(year from ds.orderdate) clientyear,extract(month from ds.orderdate) clientmonth,ds.purchasesno,t1.goodsno,t1.area,t1.targetamount,t1.goodsname
from DRP_SALESORDER ds left join
(select dc.area,dcs.clientyear,dcs.clientmonth,dcs.goodsno,dcs.clientno,dcs.targetamount,dcs.goodsname
from drp_client dc left join drp_client_salestarget dcs
on dcs.clientno = dc.clientno) t1
on ds.purchasesno = t1.clientno) t2
on sd.goodsno = t2.goodsno
group by t2.area,t2.clientyear,t2.clientmonth,t2.goodsno,t2.goodsname,t2.targetamount

这样就可以了
更多追问追答
追问
高手啊...这是为什么呢... 其实我更想利用一个分组 是不是不可能的..
追答
除了进行分组的字段以外的字段必须做聚合函数
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式