“GROUP BY” Function
The “GROUP BY” statement is used with the aggregate functions such as SUM and COUNT to group the result-set by one or more columns.
Again, let’s use the same ”world_data” dataset to illustrate this.
Consider that we want to find the total gdp of each continent from this dataset.
We will write the following query:
SELECT continent, SUM(gdp)
GROUP BY continent
The output will be:
“ORDER BY” Function
The ORDER BY Function is used to sort our output in ascending or descending order.
For instance, let’s look at the case where we need to query the gdp of the countries, ranked in descending order.
We will use the following query:
SELECT name, gdp
ORDER BY gdp DESC
*Note the use of DESC here. Ascending order is assumed in Hive SQL unless the DESC keyword is used.
The output will be :