目 录(DQL)
(六)SQL | 数据查询语言DQL | 基础查询https://blog.csdn.net/lvmealn/article/details/131346044
(七)SQL | 数据查询语言DQL | 条件查询https://blog.csdn.net/lvmealn/article/details/131346294
(八)SQL | 数据查询语言DQL | 聚合函数https://blog.csdn.net/lvmealn/article/details/131351460
(九)SQL | 数据查询语言DQL | 分组查询https://blog.csdn.net/lvmealn/article/details/131352661
(十)SQL | 数据查询语言DQL | 排序查询https://blog.csdn.net/lvmealn/article/details/131353679
(十一)SQL | 数据查询语言DQL | 分页查询https://blog.csdn.net/lvmealn/article/details/131354123
(十二)SQL | 数据查询语言DQL | 执行顺序https://mp.csdn.net/mp_blog/creation/editor/131365963
练 习
数据库:world(MySQL自带),数据表:city(MySQL自带)
- 查询id为1,10,100的city信息
- 查询countrycode以A开头,population在200000~400000之间的name为5个字的city信息
- 统计population少于100000的,各countrycode的city数量
- 查询population小于等于250000的城市信息,并按countrycode升序排序,其次按name升序排序
- 查询countrycode以A开头,population在200000~400000之间的前10个city的信息,并按countrycode升序排序,其次按name升序排序
use world;
show tables;
desc city;
select * from city;
-- 1. 查询id为1,10,100的city信息
select * from city where id in(1, 10, 100);
-- 2. 查询countrycode以A开头,population在200000~400000之间的name为5个字的city信息
select * from city
where countrycode like 'a%'
and population between 200000 and 800000
and name like '_____';
-- 3. 统计population少于100000的,各countrycode的city数量
select countrycode, count(id) from city
where population < 100000
group by countrycode;
-- 4. 查询population小于等于250000的城市信息,并按countrycode升序排序,其次按name升序排序
select * from city
where population <= 250000
order by countrycode, name;
-- 5. 查询countrycode以A开头,population在200000~400000之间的前10个city的信息,并按countrycode升序排序,其次按name升序排序
select * from city
where countrycode like 'a%'
and population between 200000 and 800000
order by countrycode, name
limit 10;
不总结=白学
THE END