1, the most simple query
SELECT * from Car;
2. Query the specified column
Select Name,oil,powers from Car;
3, change the name of the listed names
Select name as ' car name ', oil as ' fuel quantity ', powers as ' power ' from car;
4. Search by condition
Select Name,oil,powers from car where oil = 8.7;
5. Multi-Criteria Query
Select name oil,powers from car where oil = 8.7 or powers = 160;
Select name oil,powers from car where oil = 8.7 and powers = 160;
6. Scope Query
SELECT * from car where price>=40 and price<=60;
SELECT * from car where price between and 60;
7. Discrete query
SELECT * from car where powers = Powers = or powers = 170;
SELECT * from car where powers in (130,150,170);
SELECT * from car where powers not in (130,150,170);
8. Fuzzy Query
SELECT * from car where name like '% BMW% '; % number is all characters
SELECT * from car where name like ' _ BMW '; _ Number is a character
9. Sort query ASC Ascending desc Descending order Sort the result set
SELECT * FROM car order by oil ASC;
SELECT * FROM car order by oil desc;
10, to repeat the query distinct
Select distinct brand from car;
11, paging query
SELECT * FROM Car limit 10, 5; The first number indicates the number of skipped bars, and the second number indicates the number of bars to show after the jump.
n represents the number of pages, and m indicates the numbers of bars displayed per page
Limit (n-1) *m,m;
12. Aggregate function Query
Count (column name) total number of meanings
SUM (column name) meaning of sum
AVG (column name) mean meaning
Max (column name) min (column name)
Select COUNT (*) from car;
Select SUM (price) from car;
Select AVG (price) from car;
Select Max (price) from car;
Select min (price) from car;
=========================================================================================
Delete and change
1. Adding data from a table
INSERT into car values (', ', ', ', ');
Insert INTO car (field 1, value 1) VALUES (field 2, value 2);
Insert into car set character 1, value 1 vables (character 2, value 2);
2. Modify table Data
Update car SET field 1 = value where field 2 (To see field type) = value 2
3. Delete table data
Delete from table name where field 1 = value 1
PHP Key 3---Simple query, add and revise