首页新闻招聘找找看知识库

SQL 数据查询 查询 下级的数据 以及自己的数据

0
悬赏园豆:10 [已关闭问题] 关闭于 2018-02-26 19:14

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)  

落幕。的主页 落幕。 | 初学一级 | 园豆:21
提问于:2018-02-13 17:35

表结构和业务需求简单讲一下,你这红色蓝色,谁知道是啥....

默卿 4个月前

@默卿: 红色的 条件 就是查询的 下级的数据 蓝色就是自己数据

落幕。 4个月前

@默卿: 主要目地就是 查询下级 申请的会议 以及自己申请的会议 信息

落幕。 4个月前
< >
分享
所有回答(1)
0

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)))

落幕。 | 园豆:21 (初学一级) | 2018-02-26 19:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册