I have columns in a table like this:
race | active
===============
asian | false
black | true
asian | false
white | true
asian | false
black | false
asian | false
white | false
asian | false
black | true
black | true
asian | false
white | true
asian | false
black | false
I need to calculate the count like
white-active : 2
asian-active :
black-active :
asian-inactive :
white-inactive :
black-inactive :
How can I achieve this in SQL Server 2008?
You can try this code:
SELECT race + '-active : ' + CAST(count(active) OVER(PARTITION BY race) AS VARCHAR) output
FROM Your_Table WHERE active='true'
union all
SELECT race + '-inactive : ' + CAST(count(active) OVER(PARTITION BY race) AS VARCHAR) output
FROM Your_Table WHERE active='false'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments