【问题标题】:merging rows in SQL LISTAGG合并 SQL LISTAGG 中的行
【发布时间】:2022-10-05 23:34:26
【问题描述】:

我正在尝试使用 LISTAGG 合并 sql 中的行,但是得到的错误消息不是按函数分组

select
tbc.idattribute,
tbc.idclient,
tbc.idclientattribute,
tbc.idattributetype,
tbl.vcdescription,
LISTAGG(tb.vclongdescription, \'; \') WITHIN GROUP(ORDER BY tbc.idclient) \" test_consent\",
person_id
from
tbclientattribute tbc, tblookupheader tbl, tbclient, tblookupdetail tb
where tbc.idattributetype = tbl.idlookupheader (+)
and tbclient.idclient = tbc.idclient (+)
and tbc.idattribute = tb.idlookupdetail(+)
group by person_id
order by person_id
  • 请标记您正在使用的数据库。

标签: sql merge listagg


【解决方案1】:

我不确定合并是什么意思,但是对于该选择语句,您需要在 GROUP BY 中包含所有选定的变量才能使其工作。像这样的东西:

select
tbc.idattribute,
tbc.idclient,
tbc.idclientattribute,
tbc.idattributetype,
tbl.vcdescription,
LISTAGG(tb.vclongdescription, '; ') WITHIN GROUP(ORDER BY tbc.idclient) " test_consent",
person_id
from
tbclientattribute tbc, tblookupheader tbl, tbclient, tblookupdetail tb
where tbc.idattributetype = tbl.idlookupheader (+)
and tbclient.idclient = tbc.idclient (+)
and tbc.idattribute = tb.idlookupdetail(+)
group by person_id, tbc.idattribute,tbc.idclient,tbc.idclientattribute,tbc.idattributetype,tbl.vcdescription
order by person_id;

【讨论】:

    猜你喜欢
    • 2021-07-25
    • 2019-10-02
    • 1970-01-01
    • 2011-03-23
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多