3.DQL
3.1脚本模板
SELECT [DISTINCT] select_expr, select_expr, ...
FROM table_reference [WHERE where_condition]
[GROUP BY col_list [HAVING condition]]
[ CLUSTER BY col_list | [DISTRIBUTE BY col_list] [SORT BY| ORDER BY col_list] ]
[LIMIT number]
DISTRIBUTE BY col_list
以指定字段作为 key 作 hash partition,保证相同的 key会到同一个reduce 去处理。
Sort By col_list
以指定字段作为单个 reduce 排序的 key,保证单个reduce 内的 key 有序排列输出。
Order By col_list
只会生成一个 reduce 任务,对全部排序
CLUSTER BY col_list
以指定字段作为 key 做 hash partition,保证相同 key 会到同一个reduce 去处理。该命令相当于 distributed by col_list 和 sort by col_list 的联合使用。
3.2典型样例
查询所有记录
select * from student;
加入 where 查询条件
select * from student where id=‘001’;
加入 limit 限制
select * from student where id='001' limit 3;
升降序:
select * from student where id='001' order by come_date desc limit 3;