0

通过连接两个表的 SELECT 语句的结果如下 -

Col 1   |  Col 2    |  Col 3   |  Col 4
 ----------------------------------
sample11| sample12  | sample13 | sample14
sample11| sample12  | sample23 | sample24
sample11| sample12  | sample23 | sample34
sample11| sample12  | sample43 | sample44

如何对第 4 列中的第 2 行和第 3 行的值进行分组和连接(基于第 3 列中的不同值),以使结果如下 -

Col 1   |  Col 2    |  Col 3   |  Col 4
 ----------------------------------
sample11| sample12  | sample13 | sample14
sample11| sample12  | sample23 | sample24, sample34
sample11| sample12  | sample43 | sample44
4

1 回答 1

2

如果您使用的是 oracle 11g

SELECT  "Col 1", "Col 2", "Col 3", 
        LISTAGG("Col 4", ',') WITHIN GROUP (ORDER BY "Col 1") AS "Col 4"
FROM    TableName
GROUP   BY "Col 1", "Col 2", "Col 3"
于 2013-04-25T08:06:20.860 回答