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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -