语法: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排序时在最后