以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  sum后相同行怎么没合并  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=120725)

--  作者:yetle
--  发布时间:2018/6/22 15:25:00
--  sum后相同行怎么没合并
SELECT c.Goodsxl as 系列名, c.Gyno as 物供号, c.ZDNO as 制单号, B.Orderno as 订单号, B.MakeGro as 班组, B.Ftyno  AS 款号,c.ClientStyle as 客款号,b.QCType  as 不合格原因, Sum(Isnull(b.num,0)) as 返工件数
 F ROM Qc_Main A LEFT JOIN QC_ReturnMake B ON A.ID=B.UpID left join pq_main C ON   B.Orderno =C.ORDERNO
 WHERE   C.ZDNO=\'18011514\' and Isnull(b.num,0) >0
GROUP BY c.Goodsxl,c.Gyno,c.ZDNO,B.Orderno,B.MakeGro,B.Ftyno,c.ClientStyle,B.QCTYPE
ORDER BY Sum(Isnull(b.num,0))desc
出来的结果是

图片点击可在新窗口打开查看此主题相关图片如下:未命名.png
图片点击可在新窗口打开查看


--  作者:有点甜
--  发布时间:2018/6/22 16:12:00
--  

订单号明显不相同,怎么合并?要不你就不要加上订单号。


--  作者:yetle
--  发布时间:2018/6/25 10:16:00
--  
可以做到合并相同制单号不同订单号的不合格数量吗?(我通过订单号左关联pq_main,必不可少的表)
[此贴子已经被作者于2018/6/25 10:17:59编辑过]

--  作者:有点甜
--  发布时间:2018/6/25 10:24:00
--  

删除红色代码

 

SELECT c.Goodsxl as 系列名, c.Gyno as 物供号, c.ZDNO as 制单号, B.Orderno as 订单号, B.MakeGro as 班组, B.Ftyno  AS 款号,c.ClientStyle as 客款号,b.QCType  as 不合格原因, Sum(Isnull(b.num,0)) as 返工件数
 F ROM Qc_Main A LEFT JOIN QC_ReturnMake B ON A.ID=B.UpID left join pq_main C ON   B.Orderno =C.ORDERNO
 WHERE   C.ZDNO=\'18011514\' and Isnull(b.num,0) >0
GROUP BY c.Goodsxl,c.Gyno,c.ZDNO,B.Orderno,B.MakeGro,B.Ftyno,c.ClientStyle,B.QCTYPE
ORDER BY Sum(Isnull(b.num,0))desc