SQL执行顺序
sql 查询语句的所有关键词
SELECT DISTINCT column, AGG_FUNC(column_or_expression), …
FROM mytable
JOIN another_table
ON mytable.column = another_table.column
WHERE constraint_expression
GROUP BY column
HAVING constraint_expression
ORDER BY column ASC/DESC
- from
- join on
- where
- group by
- having
- select
- distinct
- order by
- limit
也解释了出现group by的select只能使用聚合函数或者出现在group by的字段中
group by后select有限制的原因是
因为group by后所有的属性都是属于集合,而不属于个体.如果不对select的字段加以限制,会导致查询出来的结果无意义.
例子:
查询一个班的最大年龄是有意义的,但是查询一个班的年龄是无意义的.
因为年龄只属于个体,不属于集合.


浙公网安备 33010602011771号