Syntax Order :
Select DISTINCT field 1, Field 2, Field 3 from library. Table
Where condition
GROUP BY group conditions
Having the filter # execution order, this step returns to running the SELECT statement before running the order by
Order by Sort Field
Limit n; # limits the number of bars to print to the screen
Where required before group BY, the aggregate function is not available
Hanving required after group BY, aggregate functions are available
An aggregate function, such as SELECT COUNT (ID), can be used after select from employee
Execution Order :
From->where->group By->having->distinct->order By->limit
# GROUP BY
Set mysql> set global sql_mode= "only_full_group_by"; #select只能取分组的字段
Select post from the employee group by post, but not select * FROM Employee GROUP by post;
# Group_concat
Link the value of a field in a record of group by, such as Select Post,group_concat (name) from the employee group by post;
# having
SELECT * from the employee GROUP by Post have the count (id) <2;
# ORDER BY
SELECT * from-Employee ORDER BY-age desc,id ASC;
# limit
SELECT * FROM Employee limit 0, 5;
SELECT * FROM Employee limit 5, 5; # pagination
Single-table query of SQL statements