日期:2014-05-18 浏览次数:20452 次
SELECT TOP 1 SUM(QTY) FROM MRT WHERE JOBNO=RESVT.JOBNO AND MRT.CODE=RESVT.CODE AND P_CODE=RESVT.P_CODE
SELECT TOP 1 SUM(KT.QTY) FROM KT INNER JOIN KTUDF ON(KT.ITEMNO=KTUDF.ITEMNO AND KT.KINNO=KTUDF.KINNO) WHERE KT.KTYPE='02' AND KTUDF.GDH=(CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END) AND KT.CODE=RESVT.CODE
select sum(n.col1+m.col1) col from ( SELECT TOP 1 SUM(QTY)col1 FROM MRT WHERE JOBNO=RESVT.JOBNO AND MRT.CODE=RESVT.CODE AND P_CODE=RESVT.P_CODE )m, ( SELECT TOP 1 SUM(KT.QTY)col1 FROM KT INNER JOIN KTUDF ON(KT.ITEMNO=KTUDF.ITEMNO AND KT.KINNO=KTUDF.KINNO) WHERE KT.KTYPE='02' AND KTUDF.GDH=(CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END) AND KT.CODE=RESVT.CODE )n
select sum(n.col1+m.col1) col from ( SELECT TOP 1 SUM(QTY)col1 FROM MRT WHERE JOBNO=RESVT.JOBNO AND MRT.CODE=RESVT.CODE AND P_CODE=RESVT.P_CODE )m, ( SELECT TOP 1 SUM(KT.QTY)col1 FROM KT INNER JOIN KTUDF ON(KT.ITEMNO=KTUDF.ITEMNO AND KT.KINNO=KTUDF.KINNO) WHERE KT.KTYPE='02' AND KTUDF.GDH=(CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END) AND KT.CODE=RESVT.CODE )n where m.col=n.col --你的关联条件
------解决方案--------------------
select sum(col1+col2) col from ( col1=(SELECT TOP 1 SUM(QTY)col1 FROM MRT WHERE JOBNO=RESVT.JOBNO AND MRT.CODE=RESVT.CODE AND P_CODE=RESVT.P_CODE ), col2=(SELECT TOP 1 SUM(KT.QTY)col1 FROM KT INNER JOIN KTUDF ON(KT.ITEMNO=KTUDF.ITEMNO AND KT.KINNO=KTUDF.KINNO) WHERE KT.KTYPE='02' AND KTUDF.GDH=(CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END) AND KT.CODE=RESVT.CODE ))