SQLServer LEFT JOIN 表中的第一条

SELECT  fra.FundsRequestAnswerID , utt.UserTaskID, fra.CreatedBy
FROM    FundsRequestAnswers fra
        LEFT JOIN WorkflowInstances AS wi ON fra.FundsRequestAnswerID = wi.ObjectID AND wi.ObjectType = 'FundsApply'
        LEFT JOIN ( SELECT  ut.WorkflowInstanceID ,
                            MAX(ut.UserTaskID) AS UserTaskID
                    FROM    dbo.UserTasks ut
                    WHERE   ut.TaskID = '1021218'
                            AND ut.UserID = @UserID
                            AND ut.DeletedDate IS NULL
                    GROUP BY ut.WorkflowInstanceID
                  ) utt ON utt.WorkflowInstanceID = wi.WorkflowInstanceID
WHERE   fra.ProposedProjectID = 0 AND fra.FundsTypeCode = 'Verify';

posted @ 2022-03-18 09:52  xuxuzhaozhao  阅读(427)  评论(0编辑  收藏  举报