Ваши базовые данные:
hive> create table tx1(date1 date,department string,value int) row format delimited fields terminated by ',';
OK
Time taken: 1.172 seconds
hive> load data local inpath '/home/vivekanand/vivek/hive/test.dat' into table tx1;
Loading data to table default.tx1
OK
Time taken: 0.727 seconds
hive> select * from tx1;
OK
2017-01-02 A 30
2017-01-02 B 60
2017-01-02 C 10
2017-01-02 D 40
2017-01-03 C 20
2017-01-03 D 150
2017-01-03 E 100
2017-01-03 F 20
Time taken: 1.89 seconds, Fetched: 8 row(s)
Вы можете использовать аналитическую функцию здесь, как показано ниже:
select date1,department,value
from(select date1,department,value,rank() over(partition by date1 order by value desc) f from tx1) k
where f=1;
Выход:
Total MapReduce CPU Time Spent: 0 msec
OK
2017-01-02 B 60
2017-01-03 D 150
Time taken: 1.569 seconds, Fetched: 2 row(s)