【问题标题】:How to set record in one line after Group By [duplicate]Group By后如何在一行中设置记录[重复]
【发布时间】:2019-07-10 14:44:02
【问题描述】:

我想将所有记录设置在一行中,在 GroupBy 之后用, 分隔

我的意见:

+ --------- + -------------- +
| Name      | Phone Number   |
+ --------- + -------------- +
| John      | 1234567        |
| John      | 1472583        |
| John      | 3698521        |
| John      | 7896541        |
+ --------- + -------------- +

我想要的输出

+ --------- + -------------------------------+
| Name      |           Phone Number         |
+ --------- + -------------------------------+
| John      | 1234567,1472583,3698521,7896541|
+ --------- + -------------------------------+

【问题讨论】:

标签: sql oracle string-aggregation


【解决方案1】:

您正在寻找listagg():

select name, listagg(phone_number, ', ') within group (order by phone_number) as phone_numbers
from t
group by name;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-17
    • 2019-06-29
    • 1970-01-01
    • 2013-06-27
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多