我有以下 5 张桌子 -
CREATE TABLE [dbo].[MSP_EpmProject](
[ProjectUID] [uniqueidentifier] NOT NULL,
[ProjectName] [nvarchar](255) NOT NULL,
[ProjectAuthorName] [nvarchar](255) NULL,
CONSTRAINT [PK_MSP_EpmProject] PRIMARY KEY CLUSTERED
([ProjectUID] ASC))
CREATE TABLE [dbo].[Project_CI_Mapping](
[ProjectName] [nvarchar](255) NOT NULL,
[CI] [nvarchar](100) NOT NULL)
CREATE TABLE [dbo].[ca_owned_resource](
[resource_name] [nvarchar](100) NOT NULL,
[resource_description] [nvarchar](255) NULL,
[resource_family] [int] NULL,
[resource_class] [int] NOT NULL,
[resource_status] [int] NULL,
[resource_tag] [nvarchar](64) NULL)
CREATE TABLE [dbo].[DimTeamProject](
[ProjectNodeSK] [int] IDENTITY(1,1) NOT NULL,
[ProjectNodeGUID] [uniqueidentifier] NOT NULL,
[ProjectNodeName] [nvarchar](256) NULL,
PRIMARY KEY CLUSTERED
([ProjectNodeSK] ASC))
CREATE TABLE [dbo].[DimIteration](
[IterationSK] [int] IDENTITY(1,1) NOT NULL,
[IterationName] [nvarchar](256) NULL,
[IterationGUID] [nvarchar](256) NOT NULL,
PRIMARY KEY CLUSTERED
([IterationSK] ASC))
我有一个简单的查询,它试图从所有表中获取列,但它返回了重复的值。尝试 INNER JOIN 会返回重复值,并且在尝试 LEFT OUTER JOIN 时,它会为“DimIteration.IterationName”提供 NULL 值。
查询是 -
select m.ProjectName,m.ProjectAuthorName "Project Manager", p.CI,c.resource_tag "Alt CI ID", i.IterationName
from MSP_EpmProject m, Project_CI_Mapping p, ca_owned_resource c, DimTeamProject t, DimIteration i
where i.ProjectGUID = UPPER(CAST(t.ProjectNodeGUID AS NVARCHAR(256)))
and p.CI = c.resource_name
and m.ProjectName = p.ProjectName
order by m.ProjectName,m.ProjectAuthorName, p.CI,c.resource_tag, i.IterationName
可能的映射是 -
MSP_EpmProject.ProjectName = Project_CI_Mapping.ProjectName
Project_CI_Mapping.CI = ca_owned_resource.resource_name
ca_owned_resource.resource_tag = DimTeamProject.ProjectNodeName
DimIteration.ProjectGUID = UPPER(CAST(DimTeamProject.ProjectNodeGUID AS NVARCHAR(256)))
什么是合适的解决方案?
谢谢。