我想选择不同的客户,所以我写了这个查询:
SELECT
STRING_AGG( ISNULL(Concat(Year(info.[CreationDate]),'/',Trim('BS-' from info.ProjectN)) , ' '), ' ;') As 'AllProjectN'
,STRING_AGG( ISNULL(part.Designation , ' '), ' ;') As 'AllDesignation'
,STRING_AGG( ISNULL([GalvaQualityDailyFicheControle].[Quantity] , ' '), ' ;') As 'AllQuantity'
,[GalvaQualityDailyFicheControle].[CreationDate]
,(SELECT STRING_AGG( ISNULL(cust.Name , ' '), ' ;')
WITHIN GROUP (ORDER BY cust.Name)
FROM (SELECT distinct cust.Name FROM Customer)as x) AS AllCustomer
FROM [dbo].[GalvaQualityDailyFicheControle]
Inner Join GalvaQualityDailyProduction prod on prod.id=
[GalvaQualityDailyFicheControle].FK_idDailyProduction
Inner join GalvaParts part on part.id=prod.[FK_idPart]
Inner join ProjectInfoGalva info on info.id=part.IdProject
inner Join Customer cust on cust.ID=info.FK_Customer
Group By cust.Name,[GalvaQualityDailyFicheControle].[CreationDate]
但是当我运行它时,我得到了重复的客户
答案1:
SELECT
STRING_AGG( ISNULL(Concat(Year(info.[CreationDate]),'/',Trim('BS-' from info.ProjectN)) , ' '), ' ;') As 'AllProjectN'
,STRING_AGG( ISNULL(part.Designation , ' '), ' ;') As 'AllDesignation'
,STRING_AGG( ISNULL([GalvaQualityDailyFicheControle].[Quantity] , ' '), ' ;') As 'AllQuantity'
,[GalvaQualityDailyFicheControle].[CreationDate]
,STRING_AGG( ISNULL(cust.Name , ' '), ' ;') WITHIN GROUP (ORDER BY cust.Name) AS AllCustomer
FROM [dbo].[GalvaQualityDailyFicheControle]
Inner Join GalvaQualityDailyProduction prod on prod.id = [GalvaQualityDailyFicheControle].FK_idDailyProduction
Inner join GalvaParts part on part.id=prod.[FK_idPart]
Inner join ProjectInfoGalva info on info.id=part.IdProject
inner Join Customer cust on cust.ID=info.FK_Customer
Group By [GalvaQualityDailyFicheControle].[CreationDate]
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。