region class_month attendance
NY 12/1/2011 70444
NY 1/1/2012 70125
NY 2/1/2012 69582
NY 3/1/2012 71529
NY 4/1/2012 72468
NY 5/1/2012 67068
LA 3/1/2012 1638
LA 4/1/2012 3079
LA 5/1/2012 4205
我想我的結果是:
region class_month attendance
NY 1/1/2012 70125
NY 2/1/2012 69582
NY 3/1/2012 71529
NY 4/1/2012 72468
NY 5/1/2012 67068
LA 1/1/2012 0
LA 2/1/2012 0
LA 3/1/2012 1638
LA 4/1/2012 3079
LA 5/1/2012 4205
查詢
SELECT a.region
,a.class_month
,CASE
WHEN a.attendance IS NULL
THEN 0
ELSE a.attendance
END AS attendance -- this clearly isn't right
FROM dbo.mbo_monthly_attendance a
where class_month between '2012-01-01' and '2012-05-01'
我如何讓洛杉磯回來的行有0個月沒有提供的日期範圍?
感謝您的正確方向。
'COALESCE'會比簡單的' CASE'條款。 – 2013-03-11 19:10:29