select execution

Integration of diverse data sources, as marked by a constant column of this table, it is a constant need, SELECT 'king Glory' as platform, name FROM heros

书写顺序  SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ...

Execution order FROM> WHERE> GROUP BY> HAVING> SELECT field> DISTINCT> ORDER BY> LIMIT

SELECT DISTINCT player_id, player_name, count ( *) as num # sequentially. 5
the FROM Player Team the ON player.team_id the JOIN order # = team.team_id. 1
the WHERE height> 1.80 # sequence 2
the GROUP BY player.team_id order #. 3
the HAVING NUM> # 2 sequence. 4
the oRDER BY NUM # DESC order. 6
the LIMIT 2 sequence # 7

Each step will generate a virtual table, the next step as an input, invisible to the user

The first is to perform the SELECT FROM this step. At this stage, if multiple tables joint investigation, will be subjected to the following steps:
1. First the first Cartesian product by CROSS JOIN request, to give the equivalent of a virtual table VT (Virtual Table) 1-1 of;
2. By oN screening, screening based on the virtual table vt1-1 obtain virtual table vt1-2;
3. Add outer rows. If we use the connection left and right link or connection whole, will involve external line, that is, increase the line on the basis of external virtual table vt1-2 on, get virtual table vt1-3.
Of course, if we operate more than two tables, will repeat the above steps until all the tables have been processed. This process is to get our raw data.
When we got the raw data query data table, which is the ultimate virtual table vt1 , it can then be based on this
WHERE stage. At this stage, the filter will filter the results vt1 table, get virtual table vt2.
Then enter the third step and fourth step, and that is GROUP HAVING stage. In this stage, in fact, virtual table
grouping vt2 and packet filtering based on the virtual table to give an intermediate vt3 and VT4 .
Once we have completed the screening part of the conditions, you can filter field in the table extraction, which is entered into and SELECT
DISTINCT stage.
In the first stage extracts SELECT field you want, and then filter out duplicate rows in DISTINCT stage, respectively, to obtain an intermediate
virtual table vt5-1 and vt5-2 .
When we extract the data fields you want, you can sort according to the specified field, that is, ORDER BY order
segment, give virtual table VT6 .
Finally, based on the vt6, remove the recording of the specified row, i.e. LIMIT stage, the final result obtained, corresponding to a virtual table VT7 .

 

 

Guess you like

Origin www.cnblogs.com/autointerface/p/11934459.html