我像这样制作 SQL,但第二个选择没有正确计算行,并且行重复


select * from (
select distinct nationality,gender,regplacetype,count(gender) as total from population
where date_part('year',age(to_date(dateofbirth,'DDMMYYYY'))) BETWEEN  16 and 67 and gender = 'Man'
group by nationality,gender,regplacetype
) as man,
(
select distinct nationality,gender,regplacetype,count(nationality) as total from population
where date_part('year',age(to_date(dateofbirth,'DDMMYYYY'))) BETWEEN  16 and 57 and gender = 'female'
group by xnationality,gender,regplacetype) as female
with man as (
select distinct nationality,gender,regplacetype,count(gender) as total from population
where date_part('year',age(to_date(dateofbirth,'DDMMYYYY'))) BETWEEN  16 and 67 and gender = 'Man'
group by nationality,gender,regplacetype
) select * from man,
union
select distinct nationality,gender,regplacetype,count(nationality) as total from population
where date_part('year',age(to_date(dateofbirth,'DDMMYYYY'))) BETWEEN  16 and 57 and gender = 'female'
group by xnationality,gender,regplacetype

最新更新