SQL Count/Sum displaying column as rows -


i have table 4 bit columns need create report show total of "true" values each column need column names return row. examples, table contain:

column1 column2 column3 1          1      0 0          1      0 1          1      0 

the result should be:

category value column1    2 column2    3 column3    0 

the table has other columns, need specific ones

thanks

i don't know if there other approaches, following should work:

select 'column1' "category", sum(column1) "value" my_table union select 'column2', sum(column2) my_table union select 'column3', sum(column3) my_table 

here's sqlfiddle it.


Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -