我有這個查詢。它應該從作品表中返回AWARDED(1)和NOT AWARDED(0)作品的計數。如何返回2列中的計數?
Select Count(w.WorkID)as Total, w.IsAwarded, org.OrganizationName
From Works w
Inner Join MC_MemberShip.Membership.Organization org
ON org.OrganizationID= w.Organization_ID
where Convert(varchar(11), w.OpeningDate) >= Convert(varchar(11), @FromDate)
and Convert(varchar(11), w.OpeningDate) < DATEADD(day, 1, Convert(varchar(11), @ToDate))
and w.IsActive=1 and
ISNULL(w.IsAwarded,0)= 0 and w.Organization_ID= case when @OrgID= -1 then w.Organization_ID else @OrgID end
group by org.OrganizationName, w.IsAwarded
現在這個查詢返回的總計數不授予即0只,但我想在同一個查詢中獲得太多回報計數。
Organization TotalAwardedWorks TotalNotAwardedWorks
Town 1 1 2
Town 2 44 33
左對齊的SQL很難閱讀...... – jarlh
添加一些示例表格數據和預期結果 - 以及格式化文本。 – jarlh
提供樣本數據和期望的結果。 –