【问题标题】:oracle LISTAGG grouping multiple row results into one row not working. ORA-00909oracle LISTAGG 将多行结果分组为一行不起作用。 ORA-00909
【发布时间】:2020-06-21 08:06:40
【问题描述】:

我在这里看到一篇帖子,使用 LISTAGG 将多行分组为 1 列下的一行,我查看了帖子示例和 oracle 网站,但无法使查询正常工作。

在 sql developer 中,错误是 ORA-00909: invalid number of arguments

我有以下问题

select d.id, d.name, d.date_sale, d.address, d.city, d.state, d.zipcode, d.description, d.explanation, d.received_date, 
       listagg(dd.my_id, dd.customer_name, dd.category, dd.transaction_date, ';' 
       ) within group (order by dd.transaction_date)
from table1 d
left join table2 dd on d.id = dd.my_id
where d.id =1 and d.isActive =1

感谢任何帮助。

【问题讨论】:

    标签: sql oracle aggregate


    【解决方案1】:

    将这些值连接在一起并添加group by

    select d.id, d.name, d.date_sale, d.address, 
           listagg(dd.my_id || dd.customer_name || dd.category, dd.transaction_date, ';' 
                  ) within group (order by dd.transaction_date)
    from table1 d left join
         table2 dd
         on d.id = dd.my_id
    where d.id =1 and d.isActive = 1
    group by d.id, d.name, d.date_sale, d.address;
    

    【讨论】:

    • 嗨,戈登,我通过你的例子得到了它,但我的第一个选择下大约有 40 个字段,我是否将所有 40 个字段都添加到“分组依据”中?谢谢
    • @user1250264 。 . .要么使用子查询,要么使用子查询。不过,那将是一个不同的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2021-11-30
    • 2022-08-18
    相关资源
    最近更新 更多