【问题标题】:concatenate sql query result multiple rows into single row [duplicate]将sql查询结果多行连接成单行[重复]
【发布时间】:2014-02-04 21:49:41
【问题描述】:

我有以下查询(SQL)

select  x from Test
group by x
having  count(x)>1;

我想将结果连接到 一行,任何想法。 注意:对于简单的查询,我有用户 wm_concat 函数,它工作正常,但它不起作用 对于上述查询可能是因为分组。

请帮忙?

【问题讨论】:

标签: sql oracle


【解决方案1】:

这是您可以做到的一种方法。请注意,我在 listagg 函数中包含了一个参数,用于添加逗号作为分隔符,可以根据需要排除或更改:

select listagg(x, ',') 
         within group (order by x) as concatenated_result
  from (select x 
          from Test
         group by prxod_id 
         having count(x)>1
          );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    相关资源
    最近更新 更多