我正在尝试理解MySQL DBMS中SELECT
查询执行的逻辑顺序。
- FROM
- ON
- JOIN
- WHERE
- GROUP BY
- WITH CUBE或WITH ROLLUP
- HAVING
- 选择
- DISTINCT
- ORDER BY
- TOP
醇>
或者:
- FROM clause
- WHERE子句
- SELECT子句
- GROUP BY子句
- HAVING条款
- ORDER BY子句
醇>
正如你所看到的那样,两者的顺序相反,所以我开始摆弄MySQL。
表格(PROGETTO
)如下:
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| NOME_P | varchar(15) | NO | UNI | NULL | |
| NUMERO_P | int(11) | NO | PRI | NULL | |
| SEDE_P | varchar(15) | YES | | NULL | |
| NUM_D | int(11) | NO | MUL | NULL | |
+----------+-------------+------+-----+---------+-------+
数据集是:
+-----------------+----------+-----------+-------+
| NOME_P | NUMERO_P | SEDE_P | NUM_D |
+-----------------+----------+-----------+-------+
| ProdottoX | 1 | Bellaire | 5 |
| ProdottoY | 2 | Sugarland | 5 |
| ProdottoZ | 3 | Houston | 5 |
| Informatizzazio | 10 | Stafford | 4 |
| Riorganizzazion | 20 | Houston | 1 |
| Nuove opportuni | 30 | Stafford | 4 |
+-----------------+----------+-----------+-------+
所以,我发起了第一个查询:
mysql> SELECT NOME_P FROM PROGETTO GROUP BY NUM_D;
+-----------------+
| NOME_P |
+-----------------+
| Riorganizzazion |
| Informatizzazio |
| ProdottoX |
+-----------------+
我想,“好的顺序必须是第一个,但让我们再试一次......”然后我执行了:
mysql> SELECT NOME_P AS NNN FROM PROGETTO GROUP BY NNN;
+-----------------+
| NNN |
+-----------------+
| Informatizzazio |
| Nuove opportuni |
| ProdottoX |
| ProdottoY |
| ProdottoZ |
| Riorganizzazion |
+-----------------+
......这让我很困惑。