【问题标题】:How to concat values from different rows of the query? [duplicate]如何连接来自查询不同行的值? [复制]
【发布时间】:2016-01-19 21:35:52
【问题描述】:

我必须连接一列的值,根据同一张表中已知的“等级”对它们进行分组。

TAB_LOOKUP

str_name rank
en       1
bs       2
cn       3
bf       4
co       5

源表中存在的数据

Source_Tab

id    str_name
1     co
1     en
1     bf
2     bs
2     co
3     bf
3     bs

输出数据应该是这样的

id   concat_str_name
1    en | bf | co    
2    bs | co
3    bs | bf 

我可以使用 list_agg 之类的函数吗?

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    这是你想要的吗?

    select listagg(str_name, ' | ') within group (order by rank)
    from source_tab t join
         tab_lookup l
         on t.str_name = l.str_name
    group by id;
    

    【讨论】:

      猜你喜欢
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 2017-02-23
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多