sql - Group by in HIVE not working like i want -
hi trying output city playerid ab(runs).
output birth city of player had @ bats (ab) in
career.
now want cinncinati, sander01, 14432, correct. shows in 3's this. every city , player , runs, 2nd most. need 1 entry, other 2 redundant. think there did wrong group by, help? plz
cinncinati, sander01, 14432 cinncinati, sander01, 14432 cinncinati, sander01, 14432 chicago, dere90, 12324 chicago, dere90, 12324 chicago, dere90, 12324 select a.bcity,a.id, b.ab master join (select id, sum(ab) ab batting group id) b on a.id = b.id order b.ab desc limit 30;
refer distinct getting distinct result set.now coming question,join master table top row result set b.
select a.bcity,b.id,b.ab master join (select id,sum(ab) ab batting group id order ab desc limit 1 ) b on a.id = b.id
you can change limit 30 limit 1 , same result.
select a.bcity,a.id, b.ab master join (select id, sum(ab) ab batting group id ) b on a.id = b.id order b.ab desc limit 1;
note: if there multiple players same runs limit 1 not give correct answer.
Comments
Post a Comment