sql server错误消息116,如何绕过

时间:2018-04-04 14:26:09

标签: sql sql-server sql-server-2008

我的查询中有子查询问题。 在此查询中:

SELECT * 
FROM Statistic_RecordedConversations A
  JOIN (SELECT DID, max(DateTime) MaDate
        FROM Statistic_RecordedConversations
        where DID IN (
           Select OpenData as DID, QuestionID, InterviewID 
           from Surveys.dbo.Askia2363Data 
           where QuestionID = 895 
           and InterviewID in ( 
                select Surveys.dbo.Askia2363Data.InterviewID 
                from Surveys.dbo.Askia2363Interview, 
                     Surveys.dbo.Askia2363Data 
                where Surveys.dbo.askia2363Interview.InterviewID = 
                Surveys.dbo.Askia2363Data.InterviewID  
                and completed = 1 
                and QuestionID = 891 
                and ClosedData = 4685 
                and CAST(EndInterview as Date) = 
                CAST (Current_TIMESTAMP as Date)))
        GROUP BY DID ) B
      ON A.DID = B.DID
     AND A.DateTime = B.MaDate

我收到了msg 116的错误。我认为这是由于ligne 6,我不仅有一列。我不知道如何使这个查询工作。我尝试了IN的INISand,但结果太多,而不是我感兴趣的结果。

如果有人得到另一个解决方案,非常感谢! :)

1 个答案:

答案 0 :(得分:3)

您只能返回一个字段以关联IN语句内部。您只需要返回DID。

where DID IN ( Select OpenData as DID from Surveys.dbo.Askia2363Data...