mysql - Change Sub Query -
i got query this, working should work wonder how make in 1 query
select ( select count(exists) country c join special s on c.id_special = s.id join raports rap on c.id = rap.id_raport c.id_document = 7 , exists = 1 , rap.id_data = 201501 , is_id = 1 ) number_of_id_in_table_exists, ( select count(sps) country c join special s on c.id_special = s.id join raports rap on c.id = rap.id_raport c.id_document = 7 , sps = 1 , rap.id_data = 201501 , is_id2 = 1 ) number_of_id2_in_table_exists;
use case
expressions conditional counting:
select count(case when exists = 1 , is_id = 1 1 end) number_of_id_in_table_exists, count(case when sps = 1 , is_id2 = 1 1 end) number_of_id2_in_table_exists country c join special s on c.id_special = s.id join raports rap on c.id = rap.id_raport rap.id_data = 201501 , c.id_document = 7
Comments
Post a Comment