CRUD operation of MySQL table data

Insert data:
insert into 表名(列名1,列名2,列名3) values(值1,值2,值3);
//------If you insert all data, simple writing:
insert into 表名 values(值1,值2,值3);
//Batch insert:
insert into 表名 values
(值1,值2,值3),
(值1,值2,值3),
(值1,值2,值3);

Insert picture description here
Insert picture description here
Delete records:
delete from 表名 [where 条件]
//If no conditions are specified, all the data in the table will be deleted one by one.
truncate table 表名;
//First delete the table and rebuild the table to
Insert picture description here
update the table records:
update 表名 set 列名1=列的值1,列名2=列的值2 [where 条件];
//If no conditions are specified, the data in the table will be updated one by one
Insert picture description here
Insert picture description here

Insert picture description here

Query records:
select [distinct] [*] [列名1,列名2] from 表名 [where 条件]
//distinct: remove duplicate data
//where conditions: 1. Relational operator (<,>,=,<>); 2. Logical operator (and,or,not,between...and...); 3.like: fuzzy query (_: represents one character,% represents multiple characters); 4.in: obtains the value in a certain range;
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
alias query (as keyword, as keyword can be omitted):
table alias (main Used in multi-table query):
select 别名.列名1,别名.列名2 from 表名 [as] 别名;
Insert picture description here
Column alias:
select 列名1 [as] 别名1,列名2 [as] 别名2 from 表名;
Insert picture description here
select operation query : only perform operation on the query result ±*/:
select 列名 运算符号 数字 from 表名;
Insert picture description here
sort query: order by keyword
asc (default): ascend ascending order; desc: descend descending order:
Insert picture description here
aggregate function:
sum (): summation; avg(): average; count(): statistical number; max(): maximum value; min() minimum value;
note that it cannot be after the where condition, and use sub-query
Insert picture description here
grouping : group by
Insert picture description here
__having :Keywords that can be connected to aggregate functions appear after grouping;
__where:Keywords that cannot be connected to aggregate functions appear before grouping;
Insert picture description here
writing order:
__S…F…W…G…H…O
select… from… where… group by … Having… order by

执行顺序:
__F…W…G…H…S…O
from … where … group by … having … select … order by

Guess you like

Origin blog.csdn.net/weixin_46083166/article/details/105338497