2015-07-20 38 views

回答

0

這應該是非常接近:

SELECT col1 
    , CONCAT_WS(
     ' ', 
     GROUP_CONCAT(DISTINCT col2 SEPARATOR ' '), 
     GROUP_CONCAT(DISTINCT col3 SEPARATOR ' ') 
    ) as cnct 
FROM your_table 
GROUP BY col1 

See live example.

編輯:even better

SELECT CONCAT_WS(
     ' ', 
     col1, 
     GROUP_CONCAT(DISTINCT col2 ORDER BY col2 SEPARATOR ' '), 
     GROUP_CONCAT(DISTINCT col3 ORDER BY col3 SEPARATOR ' ') 
    ) as cnct 
FROM your_table 
GROUP BY col1 
0

這樣的事情。

SELECT Concat(column1, ' ', Group_concat(DISTINCT column2 SEPARATOR ' '), ' ', 
       Group_concat(DISTINCT column3 SEPARATOR ' ')) 
FROM tsts 
GROUP BY column1 

SQLFIDDLE DEMO