我是新來的,所以請耐心等待。聚合,計數,案例和條款
我正在寫一個查詢,我需要用兩個特定的值來計算的行數,
我已經使用下列以獲得在一個領域的不同值的結果,但我需要知道僅當另一個字段設置爲特定值時纔會生成結果。我把從以前的問題,關於這個站點如下:
COALESCE(count(case when CW.MAINJOBROLE = 2 THEN 1 end),0) as ALLJOBROLES_2,
coalesce(count(case when CW.MAINJOBROLE = 3 then 1 end), 0) as ALLJOBROLES_3,
coalesce(count(case when CW.MAINJOBROLE = 4 then 1 end), 0) as ALLJOBROLES_4,
coalesce(count(case when CW.MAINJOBROLE = 7 then 1 end), 0) as ALLJOBROLES_7,
coalesce(count(case when CW.MAINJOBROLE = 8 then 1 end), 0) as ALLJOBROLES_8,
coalesce(count(case when CW.MAINJOBROLE = 23 then 1 end), 0) as ALLJOBROLES_23,
coalesce(count(case when CW.MAINJOBROLE = 24 then 1 end), 0) as ALLJOBROLES_24,
coalesce(count(case when CW.MAINJOBROLE = 25 then 1 end), 0) as ALLJOBROLES_25'
作爲一個更大的查詢的一部分,我想做的事情上面只有CW.EMPLSTATUS = 1
謝謝我相信我試過這個,但必須讓我的括號不正確。 – 2014-09-22 08:51:03