我有一個表,其中包含有關某個日記的類條目的數據。我試圖按周分開結果,所以我每週都會得到這些條目的數量。但是當我按天分組時,我也會得到空值。我想用Null值省略記錄。我怎麼做?SQL Server 2014 - 如何刪除空記錄
我寫了下面的代碼:
SELECT Year(JournalDate) AS YY
,Month(JournalDate) AS MM
,FromClass
,ToClass
,(SELECT Count(JournalID)
WHERE Day(JournalDate) >= 1 AND Day(JournalDate)=7) AS CountWeek1
,(SELECT Count(JournalID)
WHERE Day(JournalDate) >= 8 AND Day(JournalDate)=14) AS CountWeek2
,(SELECT Count(JournalID)
WHERE Day(JournalDate) >= 15 AND Day(JournalDate)=21) AS CountWeek3
,(SELECT Count(JournalID)
WHERE Day(JournalDate) >= 22 AND Day(JournalDate)=28) AS CountWeek4
,(SELECT Count(JournalID)
WHERE Day(JournalDate) >= 29 AND Day(JournalDate)=31) AS CountWeek5
FROM [tblJournal]
WHERE [JournalDate] >= '2016-09-01 00:00:00.000'
AND FromClass <> ToClass
--AND CountWeek1 IS NOT Null
GROUP BY Year(JournalDate), Month(JournalDate), Day(JournalDate), FromClass, ToClass
ORDER BY YY, MM, FromClass, ToClass
但我得到空值了。我想刪除空值。
YY MM FrClass ToClass CntWk1 CntWk2 CntWk3 CntWk4 CntWk5
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL 20 NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 12 NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL 29 NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL NULL NULL
2016 9 1 2 NULL NULL NULL 25 NULL
如何省略與NULL值的記錄?
編輯:
所以我真的喜歡我的結果是這樣的:
YY MM FrmCls ToClsWk1 Wk2 Wk3 Wk4 Wk5
2016 9 1 2 12 20 29 25 0
2016 9 1 3 2 1 6 0 0
2016 9 1 4 0 1 2 0 0
2016 9 2 1 0 3 0 2 0
2016 9 2 3 74 46 84 54 0
2016 9 2 4 0 0 8 5 0
2016 9 3 2 0 813 0 0 0
空值的空白? – maSTAShuFu
或不包含Cntwk1中的所有行 - wk5? – maSTAShuFu
問題:你想要一行,除了最後一列以外的所有值嗎?或者你想要四行(每行至少有一個非空列)? – pmbAustin