select - Combine 2 counts in MySQL -


basically have 2 selects shows counts:

select count(b.i_connection_type) incoming_calls  (select i_connection        active_calls        i_connection not null )  join connections b on a.i_connection=b.i_connection b.i_connection_type=2;   select count(*) "on-net calls" active_calls i_connection = 1; 

how stick them together, 1 table like:

|on-net calls| incoming calls| ------------------------------- |      2     |  4            | 

your queries return 1 integer each, can projected on single row like:

select (select 1) a, (select 2) b; +---+---+ | | b | +---+---+ | 1 | 2 | +---+---+ 

so, nest 2 queries in new one:

select (     select count(b.i_connection_type) (          select i_connection active_calls           i_connection not null )           join connections b on a.i_connection=b.i_connection           b.i_connection_type=2 ) "incoming calls", (      select count(*) active_calls i_connection = 1 ) "on-net calls"; 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -