join - SQL Query For These Two Tables -
i have these 2 tables:
person
name gender regionid bob male 1 mary female 2 jane female 3 chris male 1 paul male 2 matt male 2 jenny female 1
region
id region 1 north 2 south 3 central
i end table this:
region male female north 2 1 south 2 1 central 0 1
i first tried resulting table region's id in there no join required:
select regionid, gender, count(name) person group regionid
but gender field coming undefined. , didn't know go there.
as tagged, i'm using alasql
javascript library.
try @ this:
select a.region , sum(case when gender = 'male' 1 else 0 end) male , sum(case when gender = 'female' 1 else 0 end) female region inner join person b on a.id = b.regionid group a.region
Comments
Post a Comment