0

免责声明 - 我对 SQL Server 的了解有限。因此,如果这是一个“愚蠢”的问题,我提前道歉。

查询的目的 - 从我们公司使用的程序的多表数据库中收集信息,并将结果存入我们的网络数据库,以便我们可以显示一些信息。

问题 - 重复信息。部分问题是数据库中有多个人员实例,因此结果以这种方式重复......而其他重复来自联接。我需要合并结果,以便只存入一个具有相同名称或代码 (ID) 的结果。我想合并其余信息,以免丢失任何可能需要的信息。

这是我的查询:

SELECT people.Code AS [athlete-id],
    people.Name AS [athlete-name],
    people.DOB AS [DOB],
    people.Division AS [agency-id],
    certifs.[Expiration date] AS [expiration-date], 
    groups.Name AS [agency-name],
    address.Addresses AS [address],
    address.City AS [city],
    address.State AS [state],
    case when tags.Field = 'ABJD86GHKXXQWA9Q'
        then tags.Value 
    end AS [restrictions], 
    case when tags.Field = 'VH2C78N9A15S059T'
        then tags.Value 
    end AS [comments]
FROM people 
LEFT OUTER JOIN certifs 
    ON people.Code = certifs.Owner 
LEFT OUTER JOIN groups 
    ON people.Division = groups.Code 
LEFT OUTER JOIN address 
    ON people.Code = address.Owner 
LEFT OUTER JOIN tags 
    ON people.Code = tags.Owner 
ORDER BY [agency-name], [athlete-name]

让我知道您可能有任何问题。我很感激帮助。

4

1 回答 1

0

如果您在 SELECT 之后和 people.Code 之前插入 DISTINCT 怎么样?

SELECT DISTINCT 
people.Code [...]
于 2012-04-09T14:23:30.913 回答