SELECT MI.MeetKey,MI.Theme,MI.MeetDate,MI.BeginTime,MI.MeetEndTime,MI.MeetRoomId,MI.ReviewStatus,SD.MainBranch,(SELECT STUFF((SELECT ',' + Name FROM MeetingUser WHERE MeetKey = MI.MeetKey FOR xml path('')),1,1,'') )as attendee FROM MeetingInformation AS MI, SponsorData AS SD where SD.MeetKey = MI.MeetKey and MI.IsDeleted = 0 and (select DepartmentID from COMMON_User where UserId=MI.UserId) in ( 310,311,312,313,314) and MI.UserId=4024
首先要查询出 红色条件的数据 -红色是下级数据 信息
其次又要把蓝色条件的数据查询出来 -蓝色的自己的数据信息
但是我这样写 查询出的数据不对 求大神指教
SELECT MI.MeetKey,MI.Theme,MI.MeetDate,MI.BeginTime,MI.MeetEndTime,MI.MeetRoomId,MI.ReviewStatus,SD.MainBranch,(SELECT STUFF((SELECT ',' + Name FROM MeetingUser WHERE MeetKey = MI.MeetKey FOR xml path('')),1,1,'') )as attendee FROM MeetingInformation AS MI, SponsorData AS SD where SD.MeetKey = MI.MeetKey and MI.IsDeleted = 0 and mi.UserId=4024
union all
SELECT MI.MeetKey,MI.Theme,MI.MeetDate,MI.BeginTime,MI.MeetEndTime,MI.MeetRoomId,MI.ReviewStatus,SD.MainBranch,(SELECT STUFF((SELECT ',' + Name FROM MeetingUser WHERE MeetKey = MI.MeetKey FOR xml path('')),1,1,'') )as attendee FROM MeetingInformation AS MI, SponsorData AS SD where SD.MeetKey = MI.MeetKey and MI.IsDeleted = 0 and (select DepartmentID from COMMON_User where UserId=MI.UserId) in ( 310,311,312,313,314)
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY MI.MeetKey ASC) AS RowNumber,MI.MeetKey,MI.Theme,MI.MeetDate,MI.BeginTime,MI.MeetEndTime,MI.MeetRoomId,MI.ReviewStatus,SD.MainBranch,(SELECT STUFF((SELECT ',' + Name FROM MeetingUser WHERE MeetKey = MI.MeetKey FOR xml path('')),1,1,'') ) as attendee FROM MeetingInformation AS MI LEFT JOIN COMMON_User AS CU ON MI.UserId = CU.UserId,SponsorData AS SD where SD.MeetKey = MI.MeetKey and MI.IsDeleted = 0 and (MI.UserId=@UserId OR (CU.DepartmentID IN (309) and CU.DepartmentID not in (309)))
表结构和业务需求简单讲一下,你这红色蓝色,谁知道是啥....
– 默卿 6年前@默卿: 红色的 条件 就是查询的 下级的数据 蓝色就是自己数据
– 落幕。 6年前@默卿: 主要目地就是 查询下级 申请的会议 以及自己申请的会议 信息
– 落幕。 6年前