没有返回任何行时,TSQL COUNT显示0

没有返回任何行时,TSQL COUNT显示0,第1张

没有返回任何行时,TSQL COUNT显示0

从Authors表开始,然后左向外部联接到documents表。这意味着您需要将条件移动到外部联接中。

SELECt [AuthorID] As "Author ID",RTRIm([AuthorFirstName]) + ' ' + RTRIm([AuthorLastName]) AS "Author", COUNT(document.ID) AS "Number of Docs Authored"FROM     Author a    LEFT OUTER JOIN document d on d.AuthorID = a.ID        AND [CompletedStatus] = 'Yes'         AND [CompletedOn] >= DATEADD(d, -365, getdate())WHERe    a.ID IN (<list of author ID's>)GROUP BY a.[ID], [AuthorFirstName], [AuthorLastName]ORDER BY [Number of Docs Signed] DESC


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4975401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存