2016-04-19 82 views
0

我在嘗試將其分開,然後查找任何單個季節中玩家參與的球隊數量以及他爲之效力的球隊數量。這讓我感到沮喪,當然我還有一個樣本低於(第二)。首當其衝是我的失敗嘗試Hive腳本,DISTINCT和SUM

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

忽略^ A,我認爲他們代表seperatpr

回答

1

空間或逗號,只列獲取球隊的計數爲每個玩家對於每年和按順序desc順序,得到1行

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