????SQL求助????
select * from bbc
if object_id( 'bbc ') is not null
drop table bbc
go
create table bbc (name nvarchar(50),region nvarchar(50),area bigint,population bigint,gdp bigint)
insert bbc select 'Albania ', 'Europe ',28728,3200000,6656000000
union all select 'Algeria ', 'Middle East ',2400000,32900000,75012000000
union all select 'Angola ', 'Africa ',1250000,14500000,14935000000
union all select 'Antigua and Barbuda ', 'Americas ',442,77000,770000000
union all select 'Argentina ', 'Americas ',2800000,39300000,146196000000
union all select 'Armenia ', 'Europe ',29743,3000000,3360000000
union all select 'Australia ', 'Asia-Pacific ',7700000,20300000,546070000000
union all select 'Austria ', 'Europe ',83871,8100000,261630000000
union all select 'Bahamas ', 'Americas ',13939,32100000,4789320000
union all select 'Eoomp ', 'Milld ',500015,0,0
union all select 'Colmoomp ',Europe, '562015 ',6233,866200000
--name 国家名称
--region 地区
--population 人口数
--gdp GDP生产总值
--显示每个地区以及该地区国家总人口不少于1000千万的国家总数
-- 给出地区中所有国家的人口总数为0的地区.
--有些国家的人口数比她的周边国家(周边国家指在同一地区的国家)要多三倍,列出这些国家和地区.
第一问题的结果(我要的结果)
region 数量
-------------- --------
Africa 1
Americas 2
Asia-Pacific 1
Middle East 1
------解决方案--------------------select region,count(1),sum(population)
from bbc
where population> =10000000
group by region
order by region
---
Africa 1 14500000
Americas 2 71400000
Asia-Pacific 1 20300000
Middle East 1 32900000
------解决方案--------------------1、
select region,sum(case when population> 10000000 then 1 else 0 end) from bbc group by region
------解决方案----------------------显示每个地区以及该地区国家总人口不少于1000千万的国家总数
理解的
select region,
sum(1) as 地区国数,
sum(case when population> =10000000 then 1 else 0 end) as 总人口不少于1千万的国家总数
from bbc
group by region
你要的
select region,
count(*) as 数量
from bbc
where population> =10000000
group by region
ps:应该是1千万,不是1000千万
------解决方案---------------------- 给出地区中所有国家的人口总数为0的地区.
select region
from bbc