增:
insert into 表名(字段,字段,字段) values(值,值,值);
insert into 表名 values(值,值,值);
insert into 表名 set 字段=值, 字段=值;
删:
delete from 表名 where id=2;
delete from 表名;
truncate table 表名;
改:
update 表名 set 字段=值,字段=值 where id=2;
查:
select * from 表名;
select 字段,字段 from 表名;
select distinct 字段,字段 from 表名; ""过滤表中重复出现的数据""
select 字段 as 别名 from 表名;
"比较运算符"
> < >= <= !=
between 10 and 100; "之间"
like 'ssa%' '%asd%' '%dfsf' "以什么开头,包含,以什么结尾"
"逻辑运算符"
and or not
select * from 表名 where 字段 between 10 and 100 order by desc; "查找10-100范围的数并降序"
select * from 表名 where 字段 in(1, 2, 3, 4,);
select * from 表名 where 字段 like '%sa%';
select * from 表名 where 字段 is null;
排序:
select * from 表名 order by 字段 ASC; "升序"
select * from 表名 order by 字段 DESC; "降序"
select * from 表名 where 字段 like '%asd%' order by 字段 ASC;
分组:
select 字段 from 表名 group by 字段;
select 字段 from 表名 group by 字段 having 条件
多表查询:
select * from 表1,表2;
inner join "内连接"
select * from 表1 inner join 表2 on 连接条件;
left join "左外连接"
select * from 表1 left join 表2 on 连接条件;
right join "右外连接"
select * from 表1 right join 表2 on 连接条件;