2014-01-06 57 views
1

File1中:標識文件與蜂房工作聯接

id interests_code 
1   1,2 
2   2,3 
3   1,4 

文件2:興趣文件

1 Football 
2 Cricket 
3 Baseball 
4 Hockey 

在這裏,在File1中,列interests_code是元素(數組)的數組,我想創建一個輸出文件爲,

id interests 
1  Football,Cricket 
2  Cricket,Baseball 
3  Football,Hockey 

是否可以在另一個表的數組的列上進行聯接?

回答

1

你最好規範你的數據庫設計。

但如果你想從當前的表結構得到結果,請嘗試:

SELECT t1.id, GROUP_CONCAT(t2.interest) AS interests 
FROM id_file t1 
LEFT JOIN interests_file t2 ON FIND_IN_SET(t2.id, t1.interests_code) 
GROUP BY t1.id 
+1

大..!這裏是演示網址:http://sqlfiddle.com/#!2/f9fb3/2 –

+0

但我已經嘗試提交HIVE中的查詢,但它看起來像函數GROUP_CONCAT不可用HIVE中。但是我遇到了COLLECT_SET。我試圖用這個來達到同樣的效果。任何幫助! – user3164854