我需要按月份和状态获取去年的销售额

2020-09-22 19:35发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)我有以下语法,但不确定如何拉20...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


我有以下语法,但不确定如何拉2017年任何人都可以帮忙

SELECT T0.State1 AS'Bill-to State',(SELECT SUM(T1.DocTotal)从OINV T1与(NOLOCK)INNER JOIN OCRD T2在T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 1 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE()))为'Jan Amt',(从(INLOCK)INNER JOIN OCRD T2 ON的情况下从OINV T1中选择SUM(T1.DocTotal) T2.CardCode = T1.CardCode其中MONTH(T1.DOCDATE)= 2 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE()))AS'FEB Amt',(SELECT SUM(T1 .DocTotal)从OINV T1和(NOLOCK)INNER JOIN OCRD T2在T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 3 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE) ()))作为'MAR Amt',(从OINV T1的(NOLOCK)INNER JOIN OCRD T2 ON T2上选择总和(T1.DocTotal).CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 4 AND T2.State1 = T0.State1和YEAR(T1.DOCDATE)= YEAR(GETDATE())以'APR Amt',(SELECT SUM(T1.DocTotal)从OINV T1与(NOLOCK)INNER JOIN OCRD T2在T2.CardCode = T1 .CardCode WHERE MONTH(T1.DOCDA TE)= 5 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE()))以'MAY AMT',(SELECT SUM(T1.DocTotal))从OINV T1与(NOLOCK)INNER JOIN OCRD T2 ON T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 6 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE()))AS'JUN Amt',(SELECT 来自OINV T1的总和(T1.DocTotal)与(NOLOCK)内连接OCRD T2在T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 7 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= 年(GETDATE()))为'JUL Amt',(从OINV T1选择总和(T1.DocTotal),在(T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 8 AND的(NOLOCK)INNER JOIN OCRD T2上) T2.State1 = T0.State1和YEAR(T1.DOCDATE)= YEAR(GETDATE()))为'Aug Amt',(SELECT SUM(T1.DocTotal)来自OINV T1,其中(NOLOCK)INNER JOIN OCRD T2在T2上。 CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 9 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE()))AS'SEP Amt',(SELECT SUM(T1.DocTotal) )从OINV T1与(NOLOCK)INNER JOIN OCRD T 2 ON T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 10 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE()))作为'OCT Amt',(SELECT SUM (T1.DocTotal)从OINV T1与(NOLOCK)INNER JOIN OCRD T2在T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 11 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR (GETDATE()))为'NOV AMT',(从OINV T1中选择SELECT SUM(T1.DocTotal),在(NOLOCK)INNER JOIN OCRD T2上T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 12 AND T2 .State1 = T0.State1和YEAR(T1.DOCDATE)= YEAR(GETDATE()))作为dbo.OCRD T0左联接dbo.OINV T1的'DEC Amt'T1 ON T1.CardCode = T0.CardCode GROUP BY T0.State1 依T0.State1订购

1条回答
me_for_i
2020-09-22 19:45

嗨,

尝试此查询,

SELECT T0.State1 AS'Bill-to State',(SELECT SUM(T1.DocTotal)从OINV T1与(NOLOCK)INNER JOIN OCRD T2在T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 1 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)作为'Jan Amt',(从(INLOCK)INNER JOIN OCRD的OINV T1中选择SUM(T1.DocTotal) T2 ON T2.CardCode = T1.CardCode其中MONTH(T1.DOCDATE)= 2 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)为'FEB Amt',( 从OINV T1和(NOLOCK)INNER JOIN OCRD T2在T2上选择总和(T1.DocTotal).CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 3 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE) = YEAR(GETDATE())-1)为'MAR Amt',(从OINV T1的(NOLOCK)INNER JOIN OCRD T2在T2上选择总和(T1.DocTotal).CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE) = 4 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)作为'APR Amt',(SELECT SUM(T1.DocTotal)从OINV T1与(NOLOCK)INNER JOIN OCRD T2 ON T2.CardCode = T1.CardCode WHERE MONTH( T1.DOCDATE)= 5 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)为'MAY Amt',(SELECT SUM(T1.DocTotal))来自OINV T1,带有( NOLOCK)T2上的内联接OCRD T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 6 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)AS' ``Jun Amt'',(从OINV T1中选择(NOLOCK)INNER JOIN OCRD T2在T2上的总和(T1.DocTotal).CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 7 AND T2.State1 = T0.State1 AND YEAR (T1.DOCDATE)=年(GETDATE())-1)为'JUL Amt',(从OINV T1中选择(SUM(T1.DocTotal)),并在(NOLOCK)INNER JOIN OCRD T2上T2.CardCode = T1.CardCode WHERE MONTH (T1.DOCDATE)= 8 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)作为'Aug Amt',(SELECT SUM(T1.DocTotal)从OINV T1与 (NOLOCK)T2上的内联接OCRD T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 9 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)AS 'SEP Amt',(使用(NOLOCK)从OINV T1中选择(SUM(T1.DocTotal) T2上的内部联接OCRD T2.CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 10 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)AS'OCT Amt ',(从OINV T1中选择(NOLOCK)INNER JOIN OCRD T2到T2上的SELECT SUM(T1.DocTotal).CardCode = T1.CardCode WHERE MONTH(T1.DOCDATE)= 11 AND T2.State1 = T0.State1 AND YEAR(T1 .DOCDATE)=年(GETDATE())-1)为'NOV Amt',(从OINV T1中选择(SUM(T1.DocTotal),其中(NOLOCK)INNER JOIN OCRD T2在T2上.CardCode = T1.CardCode WHERE MONTH(T1) .DOCDATE)= 12 AND T2.State1 = T0.State1 AND YEAR(T1.DOCDATE)= YEAR(GETDATE())-1)来自dbo.OCRD T0左联接dbo.OINV T1的'DEC Amt' = T0.CardCode GROUP BY T0.State1 ORDER BY T0.State1

此致

Nagarajan

一周热门 更多>