美文网首页
数据库(sql)语法

数据库(sql)语法

作者: 传奇小超人 | 来源:发表于2019-04-03 23:11 被阅读0次

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


查询表.png

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


where用法.png 查询指定的字段.png

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


顺序.png

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


分页查询.png
5.运算符
(1.)算术运算符:+ - * /
(2.)逻辑:或 or 与 and 非 not

(3.)比较:> < = >= <= != between and
(4.)字段 in <集合>


比较字符的运算.png 运算符.png
6.模糊查询:select * from 表名 where 字段 like '表达式';
通配符:% :0~N个字符,_:1个字符 *
is null
is not null
not between and
not in
not like
模糊搜索.png
7.别名:表的别名:select * from 表名 as t; 字段的别名:select name as '姓名' from 表名 as t;
别名.png
8.约束:约束用于限制加入表的数据的类型
主键 (primary key)= 非空(not null) + 唯一(unique)
自增 auto_increment
非空 not null
默认值 default
唯一
约束条件.png
9.删除表数据(清空)
delete from 表名;
delete from 表名 where pk(主键字段) = ?;
删除表
drop table 表名;
删库操作.png
10.查看表结构(字段、数据类型、约束),desc 表名;
查看表结构.png
11.数据备份与恢复
运行.png 导出.png

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


分组.png

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


聚合运算.png
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 限制展示条数

相关文章

网友评论

      本文标题:数据库(sql)语法

      本文链接:https://www.haomeiwen.com/subject/tgmtiqtx.html