Plsql 有没有一种方法可以分割一个带有“quot;分组方式;条款
假设我们有一个查询,它显示了以该国为第一列、以该国总人口为第二列的按国家划分的人口组 为了实现这一点,我提出了以下问题:Plsql 有没有一种方法可以分割一个带有“quot;分组方式;条款,plsql,oracle10g,analytic-functions,Plsql,Oracle10g,Analytic Functions,假设我们有一个查询,它显示了以该国为第一列、以该国总人口为第二列的按国家划分的人口组 为了实现这一点,我提出了以下问题: select i.country, count(1) population from individual i group by i.country 现在我想在该查询中再引入两列,以显示每个国家的男性和女性人口 我想要实现的目标可能与此类似: select i.country, count(1) population total_populati
select
i.country,
count(1) population
from
individual i
group by
i.country
现在我想在该查询中再引入两列,以显示每个国家的男性和女性人口
我想要实现的目标可能与此类似:
select
i.country,
count(1) population total_population,
count(1) over (partition by 1 where i.gender='male') male_population,
count(1) over (partition by 1 where i.gender='female') female_population,
from
individual i
group by
i.country
问题是
我希望你明白我的意思。请原谅我的语法和命名方式(无法知道更好的描述)。此处不需要分析函数:
select
i.country
,count(1) population
,count(case when gender = 'male' then 1 end) male
,count(case when gender = 'female' then 1 end) female
from
individual i
group by
i.country
;
请参见avg()也起作用,每个非空值都会被考虑在内