1. 常用关键字演示
user表结构(id,name,age,sex) –编号,姓名, 年龄,性别
名称 | 关键字 | 用法 |
---|---|---|
增加 | INSERT | insert into user(name,age,sex) values(值1,值2,值3); |
删除 | DELETE | delete from user where 条件; |
修改 | UPDATE | update user set 字段1=值1,字段2=值2 where 条件; |
查询 | SELECT | select * from user; |
去重 | DISTINCT | select distinct 去重字段 from user; |
在···之间 | BETWEEN | select * from user where age between 20 and 30; (查询年龄在20-30之间的用户) |
模糊匹配 | LIKE | select * from user where name like ‘张_%’; (其中_匹配 一个字符,%匹配 一个或多个) |
分页查询 | LIMIT | SELECT * FROM user LIMIT 5; (查询前 5 个记录行) |
排序 | ORDER BY | select * from user order by age;(默认从小到大的正序, asc 正序,desc倒序) |
分组 | GROUP BY | select sex,count(*) from user group by sex;(分组查询男女总人数) |
分组后筛选 | HAVING | 其实与where用法相似,having后能用聚合函数where不行,分组筛选后建议用having关键字 |
检测索引 | EXPLAIN | EXPLAIN select * from user where name=‘name’; |
待完善。。