hive脚本,与sum不同

xuo3flqw  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(299)

我试图区分,然后找到一个球员在任何一个赛季的球队数和他效力的球队数。这是绊倒我了,当然我有一个下面(第二)一个样本。第一个是我失败的尝试

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;

生产

忽略^a,我认为它们代表空格或逗号,只是列分隔符

vsnjm48y

vsnjm48y1#

得到每个球员每年的球队数量,按数量排序,得到1行

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

相关问题