Here's the HQL:
select A, B, count(*) as cnt from test_table group by A, B order by cnt desc;
The sample output is as follows:
a1 | b1 | 5
a2 | b1 | 3
a1 | b2 | 2
a2 | b2 | 1
But what I want is to do the order by
in each group of A, and the intended output is like:
a1 | b1 | 5
a1 | b2 | 2
a2 | b1 | 3
a2 | b2 | 1
Could anyone can give me some idea how to resolve this problem in just one HQL? Thanks a lot!
ORDER BY Ascending and Descending You can also specify ORDER BY <column names> ASC for ascending order and ORDER BY <column name> DESC for sorting the result in descending order or the specified column.
Simple Examples. In order to count the number of rows in a table: SELECT COUNT(*) FROM table2; Note that for versions of Hive which don't include HIVE-287, you'll need to use COUNT(1) in place of COUNT(*).
Hive uses the columns in SORT BY to sort the rows before feeding the rows to a reducer. The sort order will be dependent on the column types. If the column is of numeric type, then the sort order is also in numeric order. If the column is of string type, then the sort order will be lexicographical order.
select A, B, count(*) as cnt
from test_table
group by A, B
order by A, cnt desc;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With