哪位大神能帮忙吧下面sql给简化下?

电竞想静静 2019-04-16 03:09:45
select a.*,c.UserTypeName,c.UserTypeId,d.DEPT_NAME,d.Dept_code 
from (select *,newNum=ROW_NUMBER() over(order by User_Code)
from His_User_Dict where User_Code !='admin' and User_Dept_Code = 'HX ' ) as a
left join his_Dept_Dict d on a.User_Dept_code = d.DEPT_CODE
left join (select User_Code, User_Dept_Code, UserTypeId=stuff((select ','+ CONVERT(varchar(10), UserTypeID)
from (select bb.*,aa.User_Code,aa.User_Dept_Code
from dbo.UserInfoType aa left join dbo.UserType bb on aa.UserTypeId = bb.UserTypeId) t
where t.User_Code = a.User_Code and t.User_Dept_Code=a.User_Dept_Code for xml path('')), 1, 1, '') ,
UserTypeName=stuff((select '',''+ CONVERT(varchar(10), UserTypeName) from (select bb.*,aa.User_Code,aa.User_Dept_Code from dbo.UserInfoType aa left join dbo.UserType bb on aa.UserTypeId = bb.UserTypeId) t
where t.User_Code = a.User_Code and t.User_Dept_Code=a.User_Dept_Code for xml path('')), 1, 1, '')
from (select bb.*,aa.User_Code,aa.User_Dept_Code from dbo.UserInfoType aa left join dbo.UserType bb on aa.UserTypeId = bb.UserTypeId) a
group by User_Code, User_Dept_Code) c on a.User_Code = c.User_Code and a.User_Dept_Code = c.User_Dept_Code
where newNum between 1 and 30 order by newNum asc
;
...全文
44 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
电竞想静静 2019-04-16
  • 打赏
  • 举报
回复
今天在公司看存储过程看见一段这个代码实在是看不懂了

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧