1. Insert (add) data
- Assignment to a column
insert into 表名(列1,列2) values (值1,值2);
- To assign all the columns
insert into 表名 values (值1,值2,..,值n)
In addition to
int
the type of dataNULL
, other types of data all with''
or""
caused by
2. The data look-up table
- check sentence
select
字段列表
from
表名列表
where
条件列表
group by
分组字段
having
分组之后的条件
order by
排序
limit
分页限定
- Underlying query
- Query multiple fields
select 字段名1,字段名2... from 表名;
select * from 表名; #查询所有字段
- remove duplicates
select distinct 字段n from 表名; #去除表中字段n中的重复元素
- Calculated column
● Calcd can use a series of four operations;
●null
participation calculation, the calculation result arenull
. It may be usedifnull(表达式1,表达式2)
, if the expression 1 is null, replacing an expression put expression 1 2 - Surnamed
select 字段名1 as 别名 from 表名;
select 字段名1 别名 from 表名;
- Conditions inquiry
- where clause followed by the condition
- Operators
Operators | Features |
---|---|
>、<、<=、>=、=、<> | Greater than, less than, greater than or equal, less, equal, non- |
and 或 && | versus |
or 或 || | or |
or not! | non- |
between A and B | Between A and B (including A and B) |
in (collection) | Query data in the collection of the |
is null | Null query data (can not use = null) |
like | Fuzzy queries. Placeholders: any single character _ any number of characters% |
3. Delete the data in the table
- To delete an item in the table
delete from 表名 where 条件;
- Delete all the data in the table
delete from 表名; 逐条删除,执行效率低,不推荐使用
truncate table 表名; 删除表,再新建一个一样的,推荐使用
4. Modify the data in the table
update 表名 set 列1=值1,列2=值2,列3=值3,...,列n=值n,where 条件; #不加where条件则表中所有数据都会改变