我试图在SQL Server中创建一个视图,但由于我使用的子查询,语法不断给我带来问题。基本上我需要下面的select语句的结果在视图中。我怎么会在语法上这样做呢?
SELECT Sub_Company, GL_Account, CAST(SUM(Debits) AS DECIMAL(18,2)) AS Debits,
CAST(SUM(Credits) AS DECIMAL(18,2)) AS Credits, CAST(SUM([P&L_Impact]) AS DECIMAL(18,2)) AS [P&L_Impact], COUNT(*) AS Record_Count
FROM (SELECT *
FROM [FL_SQL_Training].[dbo].[Combined_GL]
WHERE Company = 'US' AND GL_Source = 'Consolidation'
) A
WHERE GL_Journal_Header_Description LIKE '%UK%' OR
GL_Journal_Header_Description LIKE '%CAD%' OR
GL_Journal_Header_Description LIKE '%MEX%' OR
GL_Journal_Header_Description LIKE '%Hon%'
GROUP BY Sub_Company, GL_Account