select * from bbcif 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

解决方案 »

  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
      

  2.   

    1、
    select region,sum(case when population>10000000 then 1 else 0 end) from bbc group by region
      

  3.   

    --显示每个地区以及该地区国家总人口不少于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 regionps:应该是1千万,不是1000千万
      

  4.   

    -- 给出地区中所有国家的人口总数为0的地区. 
    select region
    from bbc
    group by region
    having sum(population)=0
      

  5.   


    select region,数量=count(*) from bbc 
    where population>10000000
    group by region--result
    region                                             数量          
    -------------------------------------------------- ----------- 
    Africa                                             1
    Americas                                           2
    Asia-Pacific                                       1
    Middle East                                        1(4 row(s) affected)
      

  6.   

    --有些国家的人口数比她的周边国家(周边国家指在同一地区的国家)要多三倍,列出这些国家和地区. 
    select * from bbc a
    where exists (
    select 1 from bbc
    where region=a.region
    and population*3<a.population
    )
      

  7.   

    cefriend(青草) ( ) 信誉:100    Blog  2007-01-31 17:28:43  得分: 0  
     
     
       晕,第一题这么简介的语句,
      
     
    ------------------
    哈哈,是啊,一开始刚才那个帖子给想复杂了
      

  8.   


    --显示每个地区以及该地区国家总人口不少于1000千万的国家总数
    select region,count(1) from bbc where population>=10000000 group by region -- 给出地区中所有国家的人口总数为0的地区. 
    select region,isnull(sum(case when population=0 then 1 end),0)'人口为0的国家数' 
    from bbc a group by region--有些国家的人口数比她的周边国家(周边国家指在同一地区的国家)要多三倍,列出这些国家和地区.
    select * from bbc a where exists (
    select 1 from bbc
    where region=a.region
    and population*3<a.population
    )
    我刚刚发现你的贴啊~~晕