分数 5
全屏浏览题目
切换布局
作者 admin
单位 杭州百腾教育科技有限公司
浙江省:杭州,宁波,温州
江苏省:苏州,南京,无锡
请写sql统计出浙江省和江苏省所有人口
提示:请使用SELECT语句作答。
表结构:
create table city (
name varchar(20),
population int
);
表样例
city表:
| name | population |
|---|---|
| 杭州 | 100 |
| 温州 | 100 |
| 宁波 | 100 |
| 苏州 | 100 |
| 南京 | 100 |
| 无锡 | 200 |
输出样例:
| name | population |
|---|---|
| 浙江 | 300 |
| 江苏 | 400 |
select c.name,sum(c.population) population from
(select case a.name when '杭州' then '浙江' when '宁波' then '浙江' when '温州' then '浙江' end name,sum(a.population) population
from(select name,population from city
where name in('杭州','宁波','温州'))a
group by a.name) c
where name='浙江'
union
select d.name,sum(d.population) population from
(select case b.name when '苏州' then '江苏' when '南京' then '江苏' when '无锡' then '江苏' end name,sum(b.population) population
from(select name,population from city
where name in('苏州','南京','无锡'))b
group by b.name) d
where name='江苏'
博客围绕使用SQL统计浙江省和江苏省所有人口展开,提示使用SELECT语句作答,还给出了表结构、表样例及输出样例等信息。

1429

被折叠的 条评论
为什么被折叠?



