1
我有這樣的一個表:做交叉表在蜂房(0.9版本)
sport personId
1 1
1 2
1 3
2 1
2 4
2 6
3 1
3 3
3 6
我想獲得一個表與運動的交叉點的數量 - 這相當於僞代碼:
for sport1 in sports:
for sport2 in sports:
X[sport1,sport2] = count(intersect(sport1,sport2))
我知道我這樣做,如果我只有幾個體育:
select count(*) from (select * from table where sport = sport1) t1 join (select count(*) from table where sport = sport2) t2 on t1.personId = t2.personId;
但我想這樣做產生一張桌子,適合我所有的運動。
請注意,我在Hive 0.9上,不支持交叉連接。
謝謝!
是的,我做了雙組合,它做了詭計,儘管它沒有輸出表格。我稍後會研究python reducer。 – S4M