sql - Merge two SELECT queries into one -


i have 2 queries need count of total records difference in queries 1 field value.

example;

select count(*) group_a tbl category = 'value_a'  select count(*) group_b tbl category = 'value_b' 

how can this: (pseudo)

select count(*) group_a, count(*) group_b tbl category in ('value_a', 'value_b') 

but results this

group_a , group_b 56, 101 

i thinking case statement in query filter 2 how implement it? or there better way?

i'm doing union right wanted know if return 1 record 2 results

select sum(case when category = 'value_a' 1 else 0 end) group_a,        sum(case when category = 'value_b' 1 else 0 end) group_b     tbl     category in ('value_a', 'value_b') 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -