我想創建一個總結報告。我對CTE完全陌生。CTE問題,執行錯誤。無法創建總結報告
錯誤的詳細信息:
消息102,級別15,狀態1,行1個
附近有語法錯誤。「。
Msg 102,Level 15,State 1,Line 11
','附近的語法不正確。
代碼:
WITH T1(PlannedFY, Media_Activity_Type.[Type], ReportingQuarter, Summary, ID) AS
(
SELECT
COUNT(MediaActivities.MediaActivityId) AS [PlannedFY],
Media_Activity_Type.[Type] AS [ID],
MediaActivities.ReportingQuarter,
MediaActivities.Summary,
MediaActivities.TypeId
FROM
Media_Activity_Type
INNER JOIN
MediaActivities ON Media_Activity_Type.TypeId = MediaActivities.TypeId
GROUP BY
MediaActivities.MediaActivityId, Media_Activity_Type.[Type],
MediaActivities.ReportingQuarter, MediaActivities.Achivied,
MediaActivities.Summary, MediaActivities.TypeId
),
T2(Achieved, ID) AS
(
SELECT
COUNT(MediaActivities.Achivied) AS [Achieved],
Media_Activity_Type.TypeId AS [ID]
FROM
MediaActivities
INNER JOIN
Media_Activity_Type ON MediaActivities.TypeId = Media_Activity_Type.TypeId
GROUP BY
Media_Activity_Type.TypeId, MediaActivities.Achivied
HAVING
MediaActivities.Achivied = 1
)
SELECT
T1.*, T2.Achieved
FROM
T1
INNER JOIN
T2 ON T1.ID = T2.ID