Hive脚本,带有SUM的DISTINCT

时间:2016-04-19 06:18:18

标签: sql hadoop hive

我试图区分,然后找到一个球员在任何一个赛季和他参加过的球队数量的球队数。这让我沮丧,当然我有一个样本低于(第二)一。第一个是我失败的尝试

SELECT o.id,o.year,COUNT(DISTINCT(o.team)) b JOIN
(SELECT id, year, team FROM batting
GROUP BY id,year,team
ORDER BY id DESC
LIMIT 25) o 
0.id =b.id;



SELECT id, year, team FROM batting
GROUP BY id,year,team
ORDER BY id DESC
LIMIT 25;

产生 enter image description here

IGNORE ^ A,我认为它们代表空格或逗号,只是列seperatpr

1 个答案:

答案 0 :(得分:1)

获取每个玩家每年的团队数量,并按计数desc订购,获得1行

SELECT id, year, COUNT(DISTINCT(team)) FROM batting
GROUP BY id,year
ORDER BY COUNT(DISTINCT(team)) DESC
LIMIT 1;