1

我有一个表,其中有 2 个字段:LogidType

 +---------+---------+
 |  Logid  |  Type   |
 +---------+---------+
 |    1    |  PHP    |
 |    2    |  Mysql  |
 |    3    |  PHP    |
 |    4    |  JAVA   | 
 |    5    |  PHP    | 
 |    6    |  MYSQL  |
 +---------+---------+

我需要Logidlogs_operationtype组获取所有内容,
我需要将输出获取为:

 +------------+---------+
 |  Logid     |  Type   |
 +------------+---------+
 |    1,3,5   |  PHP    |
 |    2,6     |  Mysql  |
 |    4       |  JAVA   |
 +------------+---------+
4

2 回答 2

1

利用GROUP_CONCAT

SELECT GROUP_CONCAT(Logid) AS Logid, Type 
FROM  <tablename> 
GROUP BY Type
于 2012-12-06T07:49:59.293 回答
1
SELECT 
   group_concat(Login) as LogId,
   Type
FROM
   myTable
GROUP BY Type
于 2012-12-06T07:50:04.040 回答