Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何把线路接到哥伦布?SExt查询_Sql_Datetime_Ms Access_Sum_Pivot - Fatal编程技术网

Sql 如何把线路接到哥伦布?SExt查询

Sql 如何把线路接到哥伦布?SExt查询,sql,datetime,ms-access,sum,pivot,Sql,Datetime,Ms Access,Sum,Pivot,这里我写的查询非常简单 SELECT GeneralLedger, YEAR(ReportingDate) AS jaar, MONTH(ReportingDate) AS periode, SUM(AmountDCDebit - AmountDCCredit) AS Saldo FROM dbo.GeneralLedgerBalances GROUP BY GeneralLedger, YEAR(ReportingDate), MONTH(Reportin

这里我写的查询非常简单

 SELECT        GeneralLedger, YEAR(ReportingDate) AS jaar, MONTH(ReportingDate) AS periode, SUM(AmountDCDebit - AmountDCCredit) AS Saldo
FROM            dbo.GeneralLedgerBalances
GROUP BY GeneralLedger, YEAR(ReportingDate), MONTH(ReportingDate)
HAVING        (YEAR(ReportingDate) = 2020)
我得到的结果是

我多么希望得到这个结果:


我想获取列中的句点如何更改查询?

您可以使用条件聚合:

SELECT
    GeneralLedger, 
    YEAR(ReportingDate) AS jaar, 
    SUM(IIF(MONTH(ReportingDate) =  1, AmountDCDebit - AmountDCCredit, 0)) AS Saldo01,
    SUM(IIF(MONTH(ReportingDate) =  2, AmountDCDebit - AmountDCCredit, 0)) AS Saldo02,
    ...
    SUM(IIF(MONTH(ReportingDate) = 12, AmountDCDebit - AmountDCCredit, 0)) AS Saldo12
FROM dbo.GeneralLedgerBalances
WHERE (YEAR(ReportingDate) = 2020)
GROUP BY GeneralLedger, YEAR(ReportingDate)

您好,如果我尝试此操作,我会收到以下错误:函数参数列表中出现错误:“SUM”无法识别。无法分析查询文本。@Barendrecht。你做错了什么
SUM()
是一个非常常见的SQL函数。@Barendrecht:
SUM()
表达式之间缺少逗号。。。