日期:2014-05-18  浏览次数:20427 次

高分-求疑难SQL语句
表bbc有以下字段
name(国家名字),   region(种族),   area(所在区域),   population(人口)
问题:
显示一个国家和它所属的地区名字,这个国家的人口比同一个地区内的任何一个国家的人口的三倍还要多  



------解决方案--------------------
select
name, area
from bbc a
where not exists(
select * from bbc
where area = a.area
and name <> a.name
and population * 3 < a.population)

------解决方案--------------------
declare
@p int
select @p=population*3 from bbc

select name,area from bbc B where population> @p and area=B.area