各大虾帮忙50分(50)

  • 主题发起人 主题发起人 wisdomphg
  • 开始时间 开始时间
W

wisdomphg

Unregistered / Unconfirmed
GUEST, unregistred user!
SELECT p1.*, (P1.Qty1+ P1.Qty2 + P1.Qty3 + P1.Qty4) AS 合计from(select a.DINGD_NO as '生产编号',a.ehw_pici as '生产批次',a.ehw_xiadate as '下单日期',a.ehw_xiaqty as '下单数量',a.ehw_zgs as '个取数',SUM(CASE A.GONGX_NO WHEN '辅料' THEN (A.EHW_INQTY-A.EHW_OUTQTY) ELSE 0 END) as qty1,SUM(CASE A.GONGX_NO WHEN '领料' THEN (A.EHW_INQTY-A.EHW_OUTQTY) ELSE 0 END) as qty2,SUM(CASE A.GONGX_NO WHEN '钻孔' THEN (A.EHW_INQTY-A.EHW_OUTQTY) ELSE 0 END) as qty3,SUM(CASE A.GONGX_NO WHEN '镀铜' THEN (A.EHW_INQTY-A.EHW_OUTQTY) ELSE 0 END) as qty4,SUM(CASE A.GONGX_NO WHEN '露光' THEN (A.EHW_INQTY-A.EHW_OUTQTY) ELSE 0 END) as qty5,SUM(CASE A.GONGX_NO WHEN '蚀刻' THEN (A.EHW_INQTY-A.EHW_OUTQTY) ELSE 0 END) as qty6FROM EHW A GROUP BY a.DINGD_NO,a.ehw_pici,a.ehw_xiadate,a.ehw_xiaqty,a.ehw_zgs) as p1where (P1.Qty1+ P1.Qty2 + P1.Qty3 + P1.Qty4) <> 0以上查出的记录不会按a.dingd_no字段从A到B排列?
 
1.建议字段名称中不要包含单引号,因此 a.DINGD_NO as '生产编号' 建议更改为 a.DINGD_NO as 生产编号2.不一定,建议在最后添加 order by P1.生产编号
 
楼上说的不错~~
 
接受答案了.
 
后退
顶部