我从状态表中选择了所有状态,然后想要添加一个包含这些状态计数的新列。如果没有找到,则零应该是默认值。
SELECT
AQA.StatusId,
AQA.[Description],
NULL(Count(AQ.ActiveStatus)) AS Count
FROM
AP_QuoteActiveStatus AS AQA WITH(NOLOCK)
LEFT OUTER JOIN AP_Quote AS AQ WITH(NOLOCK) ON AQ.ActiveStatus = AQA.StatusId
ORDER BY AQA.[Description]
错误我读作:
Msg 102,Level 15,State 1,Line 4语法附近' Count'。消息 319,等级15,状态1,行6关键字附近的语法不正确 '与&#39 ;.如果此语句是公用表表达式,则为 xmlnamespaces子句或更改跟踪上下文子句,前一个 声明必须以分号结束。消息319,等级15, 状态1,第7行关键字'附近有'的语法不正确。如果这 statement是一个公用表表达式,一个xmlnamespaces子句或一个 更改跟踪上下文子句,必须是前面的语句 以分号结束。
答案 0 :(得分:1)
SELECT
AQA.StatusId,
AQA.[Description],
Count(ISNULL(AQ.ActiveStatus, '0')) AS [Count]
FROM
AP_QuoteActiveStatus AS AQA WITH(NOLOCK)
LEFT OUTER JOIN AP_Quote AS AQ WITH(NOLOCK)
ON AQ.ActiveStatus = AQA.StatusId
GROUP BY AQA.StatusId, AQA.[Description]
ORDER BY AQA.[Description]