isly_baby()的也不对呢,今天我写出来了
方法一:
select t1.name,t2.region
from
(select a.name,b.region,a.population from bbc a,
(select region,max(population) population
from bbc
group by region ) b
where a.region=b.region
and a.population=b.population
) t1,
(SELECT region,max(population) population
FROM bbc
where population not in (SELECT max(population)
FROM bbc
group by region)
group by region) t2
where t1.region=t2.region
and t1.population>3*t2.population
方法二:
select a.name,a.region from (SELECT *
FROM (SELECT a.*,ROWID,
ROW_NUMBER () OVER (PARTITION BY region ORDER BY population desc) rn
FROM bbc a)
WHERE rn =1) a,
(SELECT *
FROM (SELECT a.*,ROWID,
ROW_NUMBER () OVER (PARTITION BY region ORDER BY population desc) rn
FROM bbc a)
WHERE rn =2) b
where a.region=b.region and a.population>3*b.population
但是我写的感觉比较复杂了.请问有没有更加简单的方法啊,或者优化一下我上面的语句也行.谢谢