DQL语句:用于查询数据记录
1. 基本语法:
select 列名,列名,列名.... from 表名
联合查询:where 条件
group by 分组查询
having 分组条件
order by desc(进行想要数据的排序,从大到小) / order by asc(从小到大)
一、在表中中进行查询输出自己想要的列
select * from 表名 where id=1001 (返回表中id列中的数据等于1001,中的所有数据)
select 列名1,列名2.... from 表名 where id=1001(id列等于1001,返回的数据只有想要的输出列数据)
二、对表中的数据的模糊查询
关键字:like
通配符:%(表示任意长度的字符)
下划线_:表示任意一个字符
1.查询某表中,某列中的一个数据,数据中包含某一个字(在所有保存数据的信命中查找以郭开头的名字)
select * from 表名 where 列名(要查数据存在的列) like '郭%'
2.查询包含某个字的数据
select * from表名 where 列名 like '%郭%'
3.查询以郭开头的并且名字只有两个字的数据
select * from 表名 where 列名 like '郭_'
4.查询以某个字结尾的数据
select * from 表名 where 列名 like '%强'
三、查询的数据是想要的某个区间(比如查询称及的时候分数在60-90之间的数据)
1.select * from 表名 where 列名>60 and 列名<90
2.select * from 表名 where 列名 between 60 and 90(使用between 小数 and 大数<数大小位置关系>)
四、查询表中某一列数据并对其中数据的排序
1.select * from 表名 order by 列名 desc (降序排序)
2.select * from 表名 order by 列名 desc asc(升序排序)
五、函数查询
1.select count(1) from 表名 (统计总数)
2.select avg(列名) from 表名(列中的均值)
3.select sum(列名) from 表名(列中的总和)
4.seletc max(列名) from 表名(列中的最大值)
5.select min(列名) from 表名(列中的最小值)