[英]SQL Concat Distinct results in DB2
I am using the below statement in my query but need to select distinct values in my concatenation string. 我在查询中使用以下语句,但需要在串联字符串中选择不同的值。
substr(
xmlserialize(
xmlagg( xmltext( concat( ', ', item) ) ) as varchar( 1024 )
),
3 )
I have to do it that way because I'm running on a DB2 AS/400 database. 我必须这样做,因为我正在DB2 AS / 400数据库上运行。
Right now my results look like this: 现在,我的结果如下所示:
yellow,red,red,yellow,blue,yellow,blue,red
I need it to return only distinct values, like this: 我需要它仅返回不同的值,如下所示:
yellow,red,blue
I figured it out I used a sub select to find the results and than selected from those results the concatention 我弄清楚了我使用子选择来查找结果,然后从这些结果中选择了隐患
SELECT
CUSTOMER,
substr( xmlserialize( xmlagg( xmltext( concat( ', ', item) ) ) as varchar( 1024 ) ), 3)
FROM
(
SELECT CUSTOMER, ITEM
FROM ORDERS
WHERE
ITEM LIKE 'C%'
GROUP BY CUSTOMER, ITEM)
GROUP BY CUSTOMER;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.