Hive (23): SORT/ORDER/CLUSTER/DISTRIBUTE BY of Select Advanced Query

1 ORDER BY

ORDER BY [ASC|DESC]

The ORDER BY syntax in Hive SQL is similar to the ORDER BY syntax in the SQL language. The output results will be sorted globally, so when the bottom layer is executed using the MapReduce engine, only one reducetask will be executed. Therefore, if the number of output rows is too large, it will take a long time to complete the global sorting.

The default sort order is ascending (ASC), and can also be specified as DESC descending.

In Hive 2.1.0 and later, there is support for specifying the null type result sort order for each column in the "order by" clause. The default null sort order for ASC order is NULLS FIRST, and the default null sort order for DESC order is NULLS LAST.

---order by
--根据字段进行排序
select * from t_usa_covid19_p
where count_date = "2021-01-28"
and state ="California"
order by deaths; --默认asc null first

select * from t_usa_covid19_p
where count_date = "2021-01-28"
and state ="California"
order by deaths desc; --指定desc null last

--强烈建议将LIMIT与ORDER BY一起使用。避免数据集行数过大
--当hive.mapred.mode设置为strict严格模式时,使用不带LIMIT的ORDER BY时会引发异常。
select * from t_usa_covid19_p
where count_date = "2021-01-28"
  and state ="California"
order by deaths desc
limit 3;

</

Guess you like

Origin blog.csdn.net/u013938578/article/details/131660371