1.select *from 表名;(查询表)

2.select * from 表名 字段名1 = 字段值1 and/or 字段名2 = 字段值2;


3.select * from 表名 order by 字段名 asc(升序)/desc(降序);

4.分页查询 select * from 表名 where 字段值 limit x-1,y-x+1; 备注:例如第10到20页的内容,就是9,11

5.运算符
(1.)算术运算符:+ - * /
(2.)逻辑:或 or 与 and 非 not
(3.)比较:> < = >= <= != between and
(4.)字段 in <集合>


6.模糊查询:select * from 表名 where 字段 like '表达式';
通配符:% :0~N个字符,_:1个字符 *
is null
is not null
not between and
not in
not like

7.别名:表的别名:select * from 表名 as t; 字段的别名:select name as '姓名' from 表名 as t;

8.约束:约束用于限制加入表的数据的类型
主键 (primary key)= 非空(not null) + 唯一(unique)
自增 auto_increment
非空 not null
默认值 default
唯一

9.删除表数据(清空)
delete from 表名;
delete from 表名 where pk(主键字段) = ?;
删除表
drop table 表名;

10.查看表结构(字段、数据类型、约束),desc 表名;

11.数据备份与恢复


12.分组,group by 需要分组的字段名;

13.聚合函数:select*运算符号(数值)from 表名称;
(1.)求和sum()
(2.)统计count()
(3.)平均值avg()
(4.)最大值max()
(5.)最小值min()

14.sql优先级
书写顺序select * from 表名 where 条件1 and 条件2 or 条件3 group by 字段 order by 字段 limit x-1,y-x+1;
执行顺序
1.找表 from 表名
2.where 条件
2.1 and
2.2 or
3.排序 order by
4.select 展示字段(展示列)
5.limit 限制展示条数
网友评论