sql server 2012 - TSQL Reversing query to display cols as rows -


the following query gives me

active  inactive 3       1  select sum(case when active = 'true' 1 else 0 end) active, sum(case when active = 'false' 1 else 0 end) inactive events 

i like:

status    count active    3 inactive  1 

how can inverse this?

there no need pivoting resultset, use simple group by:

select case active when 'true' 'active'                    when 'false' 'inactive'        end status       ,count(*) count events active in ('true', 'false') group case active when 'true' 'active'                    when 'false' 'inactive'        end; 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -