gpt4 book ai didi

sql - 如何消除 DB2400 或任何 SQL 中 JSON_ARRAYAGG 中的重复行?

转载 作者:行者123 更新时间:2023-12-05 07:10:45 24 4
gpt4 key购买 nike

SQL 示例...

SELECT
ID AS HID,
JSON_ARRAYAGG(
JSON_OBJECT('sequence': TRIM(SEQUENCE),
'payer_reference_qualifier': TRIM(PAYREFQUAL),
'payer_reference_id': TRIM(PAYREFID),
'transaction_processing_status': TRIM(TRNPRCST)
)) AS H1
FROM XXXXX
WHERE ID = 7146
GROUP BY MSGHSTID;

检索到的数据:我只想检索一行而不是两行。有什么想法吗?

[
{"sequence":"1","payer_reference_qualifier":"04","payer_reference_id":"EPIDETPMT0000000001","transaction_processing_status":"E"},
{"sequence":"1","payer_reference_qualifier":"04","payer_reference_id":"EPIDETPMT0000000001","transaction_processing_status":"E"}
]

最佳答案

一个选项在子查询中使用distinct:

SELECT 
ID AS HID,
JSON_ARRAYAGG(
JSON_OBJECT(
'sequence': SEQUENCE,
'payer_reference_qualifier': PAYREFQUAL,
'payer_reference_id': PAYREFID,
'transaction_processing_status': TRNPRCST
)
) AS H1
FROM (
SELECT DISINCT
MSGHSTID,
TRIM(SEQUENCE) SEQUENCE,
TRIM(PAYREFQUAL) PAYREFQUAL,
TRIM(PAYREFID) PAYREFID,
TRIM(TRNPRCST) TRNPRCST
FROM XXXXX
WHERE ID = 7146
) t
GROUP BY MSGHSTID;

关于sql - 如何消除 DB2400 或任何 SQL 中 JSON_ARRAYAGG 中的重复行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61087447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com