sql - Bringing together coalesce, count, case and clauses -


i'm new please bear me.

i'm writing query need count number of rows 2 specific values,

i have used following result of different values in 1 field need know results if field set specific value. pulled following previous question on site:

coalesce(count(case when cw.mainjobrole = 2 1 end),0) alljobroles_2, coalesce(count(case when cw.mainjobrole = 3 1 end), 0) alljobroles_3, coalesce(count(case when cw.mainjobrole = 4 1 end), 0) alljobroles_4, coalesce(count(case when cw.mainjobrole = 7 1 end), 0) alljobroles_7, coalesce(count(case when cw.mainjobrole = 8 1 end), 0) alljobroles_8, coalesce(count(case when cw.mainjobrole = 23 1 end), 0) alljobroles_23, coalesce(count(case when cw.mainjobrole = 24 1 end), 0) alljobroles_24, coalesce(count(case when cw.mainjobrole = 25 1 end), 0) alljobroles_25' 

as part of larger query, want above if cw.emplstatus = 1

you can add condition where clause:

coalesce(count(case when cw.mainjobrole = 2 , cw.emplstatus = 1 1 end),0) alljobroles_2, 

by way, coalesce() should unnecessary. count() return 0 if there no matches.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -