字符串 char /varchar
浮点数 float /double
枚举 enum
整数 int
时间 timestamp,datetime,date,year
非空 not null
主键 primary key
唯一约束 unique
默认约束 default
外键约束 foreign key
检查约束 check
select 查询内容 from 表名
*{全部字段}
有条件 where
或 or
和 and and优先级高于or
#查询张三的全部信息
select * from 表名 where 字段名='张三'
#查询 表单名 不是 ##的全部信息
select * from 表名 where 字段名!='##'
select * from 表名 where 字段名<>'##'
select * from 表名 where not 字段名='##'
#查询不是中国的全部信息 +扩展
select * from 表名 where not 字段名='中国'
select * from 表名 where 字段名='北京' or 字段名='上海' or 字段名='广东'
select * from 表名 where 字段名 not in ('北京','上海','广东')
#查询 表单名 小于/大于/小于等于/大于等于 90的全部信息
#只能查询整数,浮点类型
select * from 表名 where 字段名 < / > / <= / >= 90
#查询 表单名 70-90 包含 的全部信息
select * from 表名 where 字段名 in between 70 and 90
#between区间 必须小在前,大在后
select * from 表名 where 字段名>=70 and 字段名<=90
#查询 表单名 70-90 不包含 的全部信息
select * from 表名 where 字段名>70 and 字段名<90
#查询未填写 字段名
select * from 表名 where 字段名='' or 字段名 is null or 字段='(Null)'
没填写 是 空值 值为(Null)
#查询填写 字段名
select * from 表名 where 字段名 is not null and 字段名!='' and 字段!='(Null)'
不是空值 不是没填写 值不为(Null)
#查询 表格中 包含‘冰’的学生信息
select * from 表名 where 字段名 like '%冰%'
#查询学生姓名中以'冰'字开头的学生信息
select * from 表名 where 字段名 like '冰%'
#查询学生姓名中以'冰'字结尾的学生信息
select * from 表名 where 字段名 like '%冰'
#查询学生姓名中第二个字是'冰'的学生信息
select * from 表名 where 字段名 like '_冰%'
#查询学生表中所有李姓的学生信息
select * from 表名 where 字段名 like '李%'
#查询学生表中姓‘王’,以‘强’字结尾的三字学生信息
select * from 表名 where 字段名 like '王_强'
#查询学生表中所有李姓的学生信息
select * from 表名 where 字段名 like '李%'or 字段名 like '%冰'
##select 查询的内容,结果 需要查询多个结果需用 , 隔开
select 字段名,字段名 from 表名 where 条件
#查询结果去重复
select distinct 字段名 from 表名
#查询结果联合去重复
select distinct 字段名,字段名 from 表名
#聚合函数 单词和括号不能有空格
#count(*) 统计查询结果的行数
#sun(字段名) 求和函数
#avg(字段名) 平均值函数
#max(字段名) 最大值
#min(字段名) 最小值
#查询 表名 中最大 字段名 和最小 字段名
select max(字段名),min(字段名) from 表名
#查询 表名 中 ##和##条件下 的结果
select count(*) from 表名 where 字段名1='字符串1' and 字段名2='字符串2'
#查询 表名 最高和最低
select max(表名),min(表名) from 字段名
#查询 ** 总分和平均分
select sum(字段名),avg(字段名) from 表名 where 字段名='**'
#查询**的数量
select count(*) from 表名 where 字段名='**'
#查询学生表中学生来自几个省份
select count(distinct 籍贯的字段名)from 学生表名
#(Group by 字段名 ) 分组 只能写在末尾
#查询xx条件中 男 女 生人数(字段名位xb)
select xb,count(*) from 表名 Group by xb
#查询每个学生的最高分,总分和平均分
# 学号 xh 成绩 cj
select xh,max(cj),sum(cj),avg(cj)from 表名 Group by xh
#查询每门课程的总分和平均分
# 课程号 kch 成绩 cj
select ,sum(cj),avg(cj) from 表名 Group by kch
#对于分组 查询----的 group by 字段名
# select 字段名 其他内容 from 表名 group by 字段名
#多次分组 group by 字段名,字段名
#注意2个字段名的前后顺序
#having
#查询个人总分大于400分的学号
select 字段名(姓名),sum(字段名(成绩)) from 表名 group by 字段名(姓名) having sum(字段名(成绩))>400
#order by 字段名 讲某一字段排序 默认升序,不显示
#desc 降序
select * from 表名 order by 字段名 desc
select * from 表名 order by 字段名 desc
#limit 数字 显示小于等于 数字的 记录
#limit 数字,数字 显示 数字+1行-数字 记录
select * from 表名 limit 3
select * from 表名 limit 3,5
select * from 表名 order by 字段名 desc limit 6,5
总结
select 查什么
from 在哪查
where 什么条件
group by 分组
having 记录分组处理后满足的查询条件
order by 排序
limit 差多少数据(几行)



