赞
踩
第1关:按条件查询单表的所有字段
本关任务:按条件查询数据表的所有字段 为了完成本关任务,你需要掌握:
如何查询数据表的所有字段
命令格式: select * from 数据表 where 查询条件
打开province数据库 第一题 查询街道信息(jdxx)数据表的开福区(qxmc)的所有字段 第二题 查询街道信息(jdxx)数据表的开福区和岳麓区(qxmc)的所有字段 第三题 查询街道信息(jdxx)数据表的长沙市(cs)的西湖街道(name)所有字段
jdxx数据表有四个字段,分别是省份(sf)、城市(cs)、区县(qxmc)、街道(name)。 例如,查询天心区(qxmc)的所有字段的值结果如图所示
开始你的任务吧,祝你成功!
- use province;
- #代码开始
- #第一题
- select * from jdxx where qxmc='开福区';
- #第二题
- select * from jdxx where qxmc='开福区'||qxmc='岳麓区';
-
- #第三题
- select * from jdxx where cs='长沙市'&&name='西湖街道';
-
- #代码结束
第2关:查询唯一值
- use province
- #代码开始
- select distinct qxmc from jdxx where sf='湖南省';
- select distinct qxmc from jdxx where cs='长沙市';
- #代码结束
- use province;
- #代码开始
- #答案1
- select count(name) from jdxx where sf='湖南省';
- #答案2
- select count(name) from jdxx where cs='长沙市';
-
- #答案3
- select count(distinct qxmc) from jdxx where sf='湖南省';
- select count(distinct qxmc) from jdxx where cs='长沙市';
-
-
-
-
- #代码结束
第4关:分组查询
- use province;
- select sf,count(*) from jdxx group by sf;
- #题目2
- select cs,count(*) from jdxx group by cs having count(*)>200;
- #题目3
- select qxmc,count(*) from jdxx where cs="长沙市" group by qxmc;
第5关:数据排序
- use province;
- #代码开始
- #第一题
- select * from jdtj order by jdgs desc limit 10;
- #第二题
- select * from jdtj order by jdgs asc limit 10;
- #第三题
- select * from jdtj where jdgs>35 order by jdgs desc,sf;
-
- #代码结束
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。