gpt4 book ai didi

sql - XML 路径分组依据 ibn SQL

转载 作者:行者123 更新时间:2023-12-02 00:36:14 25 4
gpt4 key购买 nike

我正在尝试将列中的一些值连接到一个字段中。

到目前为止,我有以下代码。

SELECT DISTINCT [customer id]
,[customer name]
,STUFF( (SELECT ',' + [description]
FROM [Invoicing].[dbo].[CurrentBillMaster]
ORDER BY [description]
FOR XML PATH('')),
1, 1, '')
,[id]
,[Section]
,[customerpo]
FROM [Invoicing].[dbo].[CurrentBillMaster]
GROUP BY [customer id], [customer name], [description],[qty],
[identifier],[FromDate],[ToDate],[id],[Section],[customerpo]

代码基本上可以工作,但是我想要串联的描述,只是为了显示该唯一 [客户 ID] 的描述

非常感谢任何帮助

最佳答案

您需要关联子查询:

SELECT  [customer id]
,[customer name]
,STUFF( (SELECT ',' + [description]
FROM [Invoicing].[dbo].[CurrentBillMaster] t
WHERE t.Customer_id = c.customer_id -- here
ORDER BY [description]
FOR XML PATH('')),
1, 1, '')
,[id]
,[Section]
,[customerpo]
FROM [Invoicing].[dbo].[CurrentBillMaster] c
GROUP BY [customer id], [customer name], [description],[qty],
[identifier],[FromDate],[ToDate],[id],[Section],[customerpo]

关于sql - XML 路径分组依据 ibn SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49421691/

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