2

我在mysql中有一个查询,结果如下:

val1_col1A  val1_col2A  val1_col1B val1_col2B
val1_col1A  val1_col2A  val2_col1B val2_col2B
val1_col1A  val1_col2A  val3_col1B val3_col2B

像这样 :

1 reza math 20
1 reza c++  19
1 reza C#   17

我的查询是:

SELECT col1A,col2A,col1B,col2B
FROM  A join B
ON col3A=col3B

我想查询它的结果如下:

val1_col1A  val1_col2A  val1_col1B,val2_col1B,val3_col1B val1_col2B,val2_col2B,val3_col2B

像这样 :

1 reza math,c++,c# 20,19,17
4

1 回答 1

1

我认为这就是你要找的:

SELECT CONCAT(GROUP_CONCAT(DISTINCT val1_col1A), 
              GROUP_CONCAT(DISTINCT val1_col2A), 
              GROUP_CONCAT(DISTINCT val1_col1B),
              GROUP_CONCAT(DISTINCT val1_col2B)) AS value
FROM table_name;
于 2012-08-10T11:52:53.327 回答