Tuesday, 17 May 2016

How to use rank() function ?


Scenario. Rank the companies by country based on their turnover in Hive ?
companyName, country, turnover

Solution
Hive>
SELECT companyName, country, turnover,
       rank() over (PARTITION BY country ORDER BY turnover DESC) as rank
FROM sales;

No comments:

Post a Comment

Note: only a member of this blog may post a comment.