对于销售报告,我通过VBA使用mssql TRANSFORM / PIVOT操作 - ADO
即使根本没有销售,我也需要打印所有照片和年份。首先是我的查询:
SQLq = "TRANSFORM SUM([Feuil$].[PRICE]) SELECT [Feuil$].[MONTH] " & _
" FROM [Feuil$]" & _
" WHERE [Feuil$].[CODEFC] = '" & CodeFC & "'" & _
" GROUP BY [Feuil$].[MONTH]" & _
" PIVOT [Feuil$].[YEAR] " & _
" IN(2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025)"
这个很好用,所有年份都是专栏,即使那些没有销售,但如果我有没有销售的monthes,我最终会缺少行
我尝试使用JOIN
语句强制使用monthes列表,但Office报告语法错误:
SQLq = "TRANSFORM SUM([Feuil$].[PRICE]) SELECT [Feuil$].[MONTH] " & _
" FROM [Feuil$]" & _
" RIGHT JOIN (1,2,3,4,5,6,7,8,9,10,11,12) AS [allmonthes] " & _
" ON ([Feuil$].[MONTH] = [allmonthes])" & _
" WHERE [Feuil$].[CODEFC] = '" & CodeFC & "'" & _
" GROUP BY [Feuil$].[MONTH]" & _
" PIVOT [Feuil$].[YEAR] " & _
" IN(2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025)"
这个不起作用,在JOIN
上报告错误
我在monthes列表之前尝试vALUES
并且其他想法无效......我应该如何更改SQL?有没有一个更好的想法,以便将所有12个monthes作为行,即使没有分组值的那些?