1. Common SQL:
A. Show databases;
B. Use xxx
C. Show tables;
D. Show columns from XXX; (describe XXX)
2. Group:
A. The group by clause can contain any number of columns. This allows grouping to be nested to provide more detailed control for data analysis.
B. If a group is nested in the group by clause, the data is summarized in the group specified at the end. In other words, when a group is created, all specified columns are calculated together (so data cannot be retrieved from individual columns ).
C. Each column listed in the group by clause must be a search column or a valid expression (but not a clustering function ). If an expression is used in select, the same expression must be specified in the group by clause. Aliases cannot be used.
D. Except for the aggregate calculation statement, each column in the SELECT statement must be given in the group by clause.
E. If the group column has a NUL value, null is returned as a group. If the column contains multiple null values, they are divided into one group.
F. The group by clause must appear after the WHERE clause and before the order by clause.
3. Differences between having and where:
Where is used to filter the data group money and having is used to filter the data group money.
4. Order by and group:
Order |
Group |
Output by sorting |
Group rows, but the output may not be the group order |
Any column can be used (or even non-selected columns) |
Only select columns or expression columns can be used, and each selection column expression must be used. |
Not necessarily required |
If you use a column (or expression) with an aggregate function, you must use |
Refer:
MySQL required
Thomesca (beicai): http://blog.csdn.net/thomescai
(Reprinted and retained)