sql - How to count one column, having a condition where an element is null and another where the element is not null? everything grouped by another element -


i have count 1 column 2 condition resulting 2 columns, grouped column. i'll show you:

select cy.name, count(noa.gz_aparat_id), count(noa.gz_aparat_id)   gz_nominalizare_aparat noa    inner join gz_nominalizare no on (no.gz_nominalizare_id = noa.gz_nominalizare_id)   inner join gz_acordacces aa on (aa.gz_acordacces_id = no.gz_acordacces_id)   inner join gz_abonament ab on (ab.gz_abonament_id = aa.gz_abonament_id)   inner join gz_punctconsum pc on (pc.gz_abonament_id = ab.gz_abonament_id)   inner join gz_iu iu on (iu.gz_punctconsum_id = pc.gz_punctconsum_id)   left outer join c_bpartner_location bplo on (ab.c_bpartner_location_id = bplo.c_bpartner_location_id)   left outer join c_location lo on (bplo.c_location_id = lo.c_location_id)   left outer join c_city cy on (lo.c_city_id = cy.c_city_id) group cy.name 

firt count must contain counts of noa.gz_aparat_id iu.gz_datapif null , second count iu.gz_datapif not null

not sure if syntax quite right oracle it's not dissimilar.

select cy.name,         sum(case when noa.gz_aparat_id null 0                   when  noa.gz_aparat_idis not null 1                   end) countnonnull,         sum(case when noa.gz_aparat_id null 1                   when  noa.gz_aparat_id not null 0                   end) countnull   gz_nominalizare_aparat noa    inner join gz_nominalizare no on (no.gz_nominalizare_id = noa.gz_nominalizare_id)   inner join gz_acordacces aa on (aa.gz_acordacces_id = no.gz_acordacces_id)   inner join gz_abonament ab on (ab.gz_abonament_id = aa.gz_abonament_id)   inner join gz_punctconsum pc on (pc.gz_abonament_id = ab.gz_abonament_id)   inner join gz_iu iu on (iu.gz_punctconsum_id = pc.gz_punctconsum_id)   left outer join c_bpartner_location bplo on (ab.c_bpartner_location_id = bplo.c_bpartner_location_id)   left outer join c_location lo on (bplo.c_location_id = lo.c_location_id)   left outer join c_city cy on (lo.c_city_id = cy.c_city_id) group cy.name 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -