使用Select进行查询时,根据查询需求不同,可以分为过滤、排序、分桶与聚合、连接,这4类型查询操作。
过滤操作包含:Where、Case When Then、Having关键词;排序是Order By、Sort By;分桶与聚合为:Distribute By、Cluster By、Group By;连接操作:Join。
Select语句的详细语法为:
SELECT [ALL | DISTINCT] <select_expression>, <select_expression>, ...
FROM [<database_name>.]<table_name>
[WHERE <where_condition>]
[GROUP BY <col_list>]
[HAVING <having_condition>]
[ORDER BY <col_name> [ASC|DESC] [, col_name [ASC|DESC], ...] ]
[CLUSTER BY <col_list> |
[DISTRIBUTE BY <col_list>] [SORT BY <col_name> [ASC|DESC] [, col_name [ASC|DESC], ...] ] ]
[LIMIT (M,)N | [OFFSET M ROWS FETCH NEXT | FIRST] N ROWS ONLY];
一般