0

运行时出现此错误:

SELECT *
FROM   repsresidents rr 
LEFT JOIN 
    (SELECT * 
     FROM residents r1 
     INNER JOIN 
           (SELECT res_peopleidy AS peopleidy, 
                   min(res_id)   AS RES_ID2 
            FROM residents 
            WHERE  res_active = '1'
            GROUP  BY res_peopleidy) r2 ON r1.res_id = r2.res_id2) r ON rr.mainpeopleidy = r.res_peopleidy
WHERE  rr.communityidy = 1

我相信问题出在min(res_id) AS RES_ID2因为res_id是PK。

residents这是表的架构

CREATE TABLE [dbo].[Residents](
    [RES_ID] [int] IDENTITY(1,1) NOT NULL,
    [RES_PeopleIDY] [varchar](50) NOT NULL,
    [RES_PhyMoveInDate] [datetime] NULL,
    [RES_CurrentUnitNumber] [varchar](50) NULL,
    [RES_CommunityIDY] [int] NULL,
    [RES_DateStarted] [datetime] NULL,
    [RES_NoPart] [int] NULL,
    [RES_LastUserUpdated] [int] NULL,
    [PER_ID] [int] NULL,
    [HEA_ID] [int] NULL,
    [LIF_ID] [int] NULL,
    [INT_ID] [int] NULL,
    [TES_ID] [int] NULL,
    [STA_ID] [int] NULL,
    [STA_Type] [int] NULL,
    [NetworkSet] [int] NULL,
    [RES_Active] [int] NULL,
    [RES_HasImage] [int] NULL,
    [RES_UpdatedImage] [int] NULL,
    [RES_Bio] [text] NULL,
    [RES_BioUpdate] [datetime] NULL,
    [RES_BioUpdateBy] [int] NULL,
    [ACT_ID] [int] NULL,
    [RES_LobbyBio] [varchar](max) NULL,
    [RES_LobbyBioUpdate] [datetime] NULL,
    [RES_LobbyBioUpdateBy] [int] NULL,
    [RES_DiscNotes1] [varchar](max) NULL,
    [RES_DiscNotes2] [varchar](max) NULL,
    [RES_DiscNotes3] [varchar](max) NULL,
    [RES_DiscNotes4] [varchar](max) NULL,
    [RES_DiscNotes5] [varchar](max) NULL,
    [RES_ExpiredDate] [datetime] NULL,
    [RES_ExpiredUser] [int] NULL,
    [RES_FinishedDate] [datetime] NULL,
    [RES_TasksSet] [int] NULL,
 CONSTRAINT [PK_Residents] PRIMARY KEY CLUSTERED 
(
    [RES_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

我究竟做错了什么?

4

1 回答 1

1

由于 Residents 没有 UNIQUEIDENTIFIERS,我不得不相信您的问题与 RepsResidents 有关。mainpeopleidy 是否有可能是唯一标识符?

于 2013-07-12T17:47:37.480 回答