【问题标题】:How to group by a column and show as one row如何按列分组并显示为一行
【发布时间】:2014-01-15 11:54:30
【问题描述】:

我有一个结构如下的表

SubId       Status  
---------------------------------------
001         Active
001         Partially Active

显示这条记录时,我需要这样显示

SubId   Status  
---------------------------------------
001     Active/Partially active

我尝试使用 distinct,但这会返回两行。

知道如何只获得 1 行而不是 2 行。我知道这很简单。我就是找不到。

【问题讨论】:

  • 如果你搜索字符串聚合,你会得到很多例子

标签: oracle group-by string-aggregation


【解决方案1】:
select subid, 
       listagg(status, '/') within group (order by null) as status
from the_table
group by subid;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    • 2017-11-17
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多