Database Management
- View all databases: show database;
- Create a database: create databse;
- Create a data view database statement: show create database database name;
- Delete the database: drop database database name;
Management table
-
View all the tables: show table;
-
Create a table:CREATE TABLE student(id INT,
NAME CHAR(20),
sex CHAR(5),
address CHAR(20),
math INT,
chinese INT); -
Lookup table structure: show create table table name; (sql to return)
desc table; -
Delete tables: drop table name;
Data Management:
- Insert data: INSERT INTO student (column name) VALUES (default value);
- change the data:set update table column name = value where conditions
- delete data:delect from table where conditions
Query data:
- select * from 表名 · distinct keywords used to remove duplicate data
Conditions inquiry
(1) display within a certain range: between. . . and. .
(2) a value consistent with multiple conditions: in
(3) fuzzy query: like% matches any number of characters _ matches one
Sort query
- Sort separate
select field names from table where field = value of the order by the field name [ASC || DESC]
ASC ASC
DES Descending - Sort combination
se'lselect field names from table where field = field name value order by ASC || DESC [1], [2 Field Name] ASC || DESC
Aggregation function:
Some of the above operation, the query is transverse, but the polymerization is longitudinal query function
max () selecting the maximum value of a
min () seeking a minimum value
AVG () column averaging the
count () lists the statistics how many record
sum () and find this column
Grouping:
select field form table gruop by field conditions [having]
group by generally to an aggregation function and use;
group by the results of the field is divided into the same group;
And where the difference between having
Interview questions:
limit Keywords:
limit 限制查询记录的条件
grammar:
limit offset,length
offset 起始行数,默认从0开始
length 返回的行数