本文介绍了MySQL的操作顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有确定的位置来查找mySQL语句的操作顺序?以下顺序正确吗?

Is there a definitive place to find order of operations for mySQL statements? Is the below order correct?

FROM子句WHERE子句GROUP BY子句HAVING子句SELECT子句ORDER BY子句

FROM clauseWHERE clauseGROUP BY clauseHAVING clauseSELECT clauseORDER BY clause

如果是这种情况,我可以在group by子句中使用SELECT类别(将first_name选择为"f_name")中定义的术语吗?

If this is the case, can I use a term defined in the SELECT clase (select first_name as "f_name") within the group by clause?

谢谢!

推荐答案

根据 MySQL文档语法如下

SELECT
[ALL | DISTINCT | DISTINCTROW ]
  [HIGH_PRIORITY]
  [STRAIGHT_JOIN]
  [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
  [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
  [ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
  [ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
  | INTO DUMPFILE 'file_name'
  | INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]

是的,您可以使用在GROUP BY子句中用AS定义的列.

Yes, you can use columns defined with AS in the GROUP BY clause.

这篇关于MySQL的操作顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:06