join - Split multiple count using in mysql with same table -


i have query in below format:

select etm.etm_taxonomy, count( pe.pp_profileid ) total_counts expertise_taxonomymaster etm left join expertise_taxonomy et on etm.etm_id = et.`et_taxonomy` left join expertise e on e.et_taxonomy = et.`et_id` left join profile_expertise pe on pe.pp_expertiseid = e.et_id pe.pp_profileid in (             select pj.pj_profileid         jobtitle_taxonomymaster jtm         left join jobtitle_taxonomy jt on jtm.jtm_id = jt.`jt_taxonomy`         left join jobtitle j on j.jt_taxonomy = jt.`jt_id`         left join profile_jobtitle pj on pj.pj_jobtitleid = j.jt_id         jtm.jtm_taxonomy = 'associate'             or jtm.jtm_taxonomy = 'partner'          )     , et_lawfirmid in (195,196) group etm_taxonomy 

and have results follows:

etm_taxonomy    total_counts advertising       18 antitrust         47     banking          258     

but need below results, count should split based on jtm.ttm_taxonomy field

etm_taxonomy    patners195  partners196     associates195   associates196 advertising       18          18              18              18 antitrust         47          47              47              47 banking          258          258            258              258   

try way:

 select etm.etm_taxonomy,     sum (case when pj_tax.jtm_taxonomy = 'associate' 1 else 0 end) associates,    sum (case when pj_tax.jtm_taxonomy = 'partner' 1 else 0 end) partners,    sum (case when pj_tax.jtm_taxonomy = 'consultant' 1 else 0 end) consultants,    sum (case when pj_tax.jtm_taxonomy = 'counsel' 1 else 0 end) counsels,  count(pe.pp_profileid ) total_counts expertise_taxonomymaster etm left join expertise_taxonomy et on etm.etm_id = et.`et_taxonomy` left join expertise e on e.et_taxonomy = et.`et_id` left join profile_expertise pe on pe.pp_expertiseid = e.et_id inner join  ( select distinct pj.pj_profileid,jtm.jtm_taxonomy jobtitle_taxonomymaster jtm left join jobtitle_taxonomy jt on jtm.jtm_id = jt.`jt_taxonomy` left join jobtitle j on j.jt_taxonomy = jt.`jt_id` left join profile_jobtitle pj on pj.pj_jobtitleid = j.jt_id jtm.jtm_taxonomy = 'associate' or jtm.jtm_taxonomy = 'partner' or jtm.jtm_taxonomy = 'consultant' or jtm.jtm_taxonomy = 'counsel' ) pj_tax on  pe.pp_profileid= pj_tax.pj_profileid et_lawfirmid =195 group etm_taxonomy 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -