2015-06-09 90 views
0

我有一個表的結構是這樣的:合併相關數據

BUSINESS NAME  CATEGORY 
ABC Inc.    Pipes 
ABC Inc.    Plumbing 
Joe's Plumbing  Plumbing 
Joe's Plumbing  Emergency 

我想重組類在同一行中,由字符分隔: 然後我會得到:

ABC Inc.    Pipes,Plumbing 
Joe's Plumbing  Plumbing,Emergency 

我該怎麼做?

謝謝!

+0

大型數據集是有任意鍵或外鍵的加入? – Rocketq

+0

http://stackoverflow.com/questions/725556/how-can-i-merge-two-mysql-tables你有沒有嘗試過這裏的任何東西? – Rocketq

回答

0

我不能得到正確的表名,其字段但你應該嘗試象下面這樣:

select GROUP_CONCAT(BUSINESS NAME) as "Business Name",CATEGORY from table_name group by CATEGORY; 
0

可以使用group_concat功能這一點。

確保您已group_concat_max_len正確設置在group_concat

select 
group_concat(distinct business_name order by business_name) as business_name, 
category 
from your_table 
group by category;