I have a simple table of the form:
id | gender | a_feature (bool) | b_feature (bool) | ... | xyz_feature (bool) |
---|
and I want to sum over all feature columns dependent on gender.
metric | male | female |
---|---|---|
a_feature | 345 | 3423 |
b_feature | 65 | 143 |
... | ... | ... |
xyz_feature | 133 | 5536 |
Is there a simple way to do this, e.g. using the information_schema.
I found only the solution below, but this is very ugly:
select
'a_feature' as feature_name,
count(case a_feature and gender = 'male') as male,
count(case a_feature and gender = 'female') as female
from table
union
select
b_feature as feature_name,
count(case b_feature and gender = 'male') as male,
count(case b_feature and gender = 'female') as female
from table
.
.
.
select
xyz_feature as feature_name,
count(case xyz_feature and gender = 'male') as male,
count(case xyz_feature and gender = 'female') as female
from table