Writing order of sql
. 1 the SELECT the DISTINCT < the select_list > 2 the FROM < left_table > . 3 < join_type > the JOIN < right_table > . 4 the ON < join_condition > . 5 the WHERE < the where_condition > . 6 the GROUP BY < group_by_list The > - MySQL from the beginning can select the alias . 7 the HAVING < having_condition > --hive began can select the alias . 8 the ORDER BY < order_by_condition > 9 LIMIT <limit_number>
The execution order of the underlying sql
1 (7) SELECT 2 (8) DISTINCT <select_list> 3 (1) FROM <left_table> 4 (3) <join_type> JOIN <right_table> 5 (2) ON <join_condition> 6 (4) WHERE <where_condition> 7 (5) GROUP BY <group_by_list> 8 (6) HAVING <having_condition> 9 (9) ORDER BY <order_by_condition> 10 (10) LIMIT <limit_number>
A, Mysql alias in use position
using the select clause alias, the group by using and following.
from Table clause aliases, and may be used later in the where.
Two, hive sql alias in use position
In having can be used and the back.
When order by sorting, you must use an alias, you can not use the expression.