语法:order by 字段名 asc/desc(升序/降序)
- 升序asc
select * from table order by a1 asc
或者
select * from table order by a1
1
2
3
order by默认是升序排序,所以asc可以省略
- 降序desc
select * from table order by a1 desc
1
3. 多字段混合排序
例如,对a1字段生序排序,a2字段降序排序
select * from table order by a1 asc, a2 desc
或者
select * from table order by a1, a2 desc
1
2
3
4. 当order by 遇到null 时,将如何排序?
在hive中认为null在排序时为最小值,即ASC排序时在最前面,DESC排序时在最后
本文详细介绍了HiveSQL和SparkSQL中的排序操作,包括升序和降序的使用,以及如何进行多字段混合排序。在Hive中,null值在排序时被视为最小值,对于ASC排序位于最前,DESC排序则位于最后。
2169

被折叠的 条评论
为什么被折叠?



