【发布时间】:2019-11-22 08:25:34
【问题描述】:
首先我要告诉你我是SQL的初学者。
我想选择与我的计划相关的所有信息,因为它的 id 将它们放在我的 C# 程序中的 DataGridView 中。
我们可以将多个 voltage levels、catenary types 等...
因此,当我尝试选择与计划相关的所有信息时,如果它具有多种电压和/或多种接触网类型,它将像这样重复行:
然后我尝试STRING_AGG,但现在我在行中有重复项,我不知道如何避免/删除它们..
这是我的查询:
SELECT TOP 20 pinfos.id
, STRING_AGG(pinfos.plan_name, '|')
, STRING_AGG (voltage.name, '|') AS vname
, STRING_AGG(catType.name, '|') AS catname
FROM [allocation_schematic.information].primary_infos pinfos
LEFT JOIN [allocation_schematic.types].plans_into_type pit
ON pinfos.id = pit.id_plan
LEFT JOIN [allocation_schematic.types].catenary_type catType
ON pit.id_type = catType.id
LEFT JOIN [allocation_schematic.types].plans_into_voltage pot
ON pinfos.id = pot.id_plan
LEFT JOIN [allocation_schematic.types].voltage voltage
ON pot.id_voltage = voltage.id
GROUP BY pinfos.id
但我想要这样:
我已经检查了this first solution 和this second one,但我不明白如何用我的查询来实现它。
有人可以帮我解决这个问题吗?自从两天以来我一直在遇到这个麻烦..
谢谢!
【问题讨论】:
标签: c# sql duplicates azure-sql-database string-aggregation