level 11
create table #country(
id int primary key identity,
code int,
Country varchar(50)
)
go
insert into #country
select 10001,'中国' union all
select 10002,'日本' union all
select 10003,'德国' union all
select 10004,'美国' union all
select 10005,'印度' union all
select 10006,'英国' union all
select 10007,'加拿大' union all
select 10008,'中国' union all
select 10009,'中国' union all
select 10010,'德国' union all
select 10011,'美国' union all
select 10012,'日本'
结果1:
select
count(case when Country='中国' or Country='印度' or Country='日本' then '亚洲' end) as 亚洲,
count(case when Country='德国' or Country='英国' then '欧洲' end) as 欧洲,
count(case when Country='美国' or Country='加拿大' then '美洲' end) as 美洲
from #country
结果2:
select
'亚洲',count(case when Country='中国' or Country='印度' or Country='日本' then '亚洲' end) from #country
union
select
'欧洲',count(case when Country='德国' or Country='英国' then '欧洲' end) from #country
union
select
'美洲',count(case when Country='美国' or Country='加拿大' then '美洲' end)
from #country
2017年02月25日 05点02分
5
level 1
后面应该还有一个所属州的ID的吧,直接group by 那个字段就可以了
2017年02月27日 08点02分
6
没错,他要是给洲的字段就容易了,没给才硬写了一个,哈哈哈
2017年02月28日 05点02分
@流星00陨落 这样的数据库设计不合理啊,那日本也可以属于中国的咯
2017年02月28日 05点02分
@Allure丶Cryme 我没设计啊,做了个临时表和他给的图一样,仅此而已。日本也可以属于中国 没看懂
2017年02月28日 06点02分
@流星00陨落 就是说如果是一个地理文盲做这个,不知道谁是亚洲,欧洲,那就尴尬啦!
2017年02月28日 06点02分