一个22表连查的SQL

select team.uid uid,team.clinename clinename,team.ulineid ulineid ,team.cteamcode cteamcode,team.idays 
idays,team.coptype coptype,team.iplanqty-team.ikeepqty-team.iqty remainingseats,team.cnation cnation,
team.cstartcity cstartcity ,team.dbgndate dbgndate,team.denddate denddate,team.cfeature cfeature ,teamprice.nprice 
nprice,teamprice.nprice2 nprice2 ,dept.ucorpid ucorpid ,corp.cname corpname ,picture.cpicpath cpicpath 
,theme.[values] themes ,tag.[values] tags ,knowledge.knowledges knowledges ,tusers.[values] userids from 
t_line line,t_team team left join (select picture.ulinkid,max(picture.cpicpath) cpicpath from t_picture 
picture where picture.ctype='线路' and picture.cdisplaytype='查询' group by picture.ulinkid) picture on picture.ulinkid=team.ulineid 
left join t_team_price teamprice on teamprice.uteamid=team.uid and teamprice.ino=1 left join t_dept dept 
on dept.uid=team.udeptid left join t_corp corp on corp.uid=dept.ucorpid left join (select * from (select 
distinct link.ulinktableid from t_customergroup_link link) a outer apply(select [values]=stuff(replace(replace((select 
link.ulinktableid uid from t_customergroup_link link left join t_customergroup groupa on groupa.uid=link.ucustomergroupid 
and link.crange=0 left join t_customer customera on customera.uid=link.ucustomerid and link.crange=2 
left join t_member membera on membera.uid=link.umemberid and link.crange=3 left join t_customergroup 
groupb on groupb.ccodepath like STUFF('%',1,0,groupa.ccodepath) and link.crange=0 or groupb.uid = link.ucustomergroupid 
and link.crange=1 left join t_customergroup_customer customergroup on customergroup.ucustomergroupid=groupb.uid 
or customergroup.ucustomerid=customera.uid left join t_member memberb on memberb.ucustomerid = customergroup.ucustomerid 
and link.crange=0 or memberb.ucustomerid = customergroup.ucustomerid and link.crange=1 or memberb.ucustomerid 
= customera.uid and link.crange=2 or memberb.uid = membera.uid and link.crange=3 left join t_customer 
customerb on customerb.uid=memberb.ucustomerid where link.ulinktableid = a.ulinktableid and link.clinktable='t_line' 
and memberb.ckind='同行' and customerb.ctype='同行' for xml auto ),'<link uid="',' '),'"/>',''),1,1,''))n) 
tusers on tusers.ulinktableid=team.ulineid left join (select * from (select distinct ulinkid from t_theme_link)a 
outer apply(select [values]= stuff(replace(replace((select t.cname cname from t_theme_link u left join 
t_theme t on u.uthemeid = t.uid where u.ulinkid = a.ulinkid for xml auto ), '<t cname="', ','), '"/>',
 ''), 1, 1, ''))n) theme on theme.ulinkid=team.ulineid left join (select * from (select distinct uinfoid 
from t_tag_link)a outer apply(select [values]=stuff(replace(replace((select t.ctagname ctagname from 
t_tag_link l left join t_tag t on l.utagid = t.uid where l.uinfoid = a.uinfoid for xml auto ), '<t ctagname="',
 ','), '"/>', ''), 1, 1, ''))n) tag on tag.uinfoid=team.uid left join ( select * from (select distinct 
ulinkid from t_knowledge_link)a outer apply(select [knowledges]= stuff(replace(replace(replace(replace((select 
k.uid uid,k.ctitle ctitle,k.cpicpath cpicpath  from t_knowledge_link l left join t_knowledge k on l.uknowledgeid 
= k.uid left join t_team_route route on route.uid=l.ulinkid where l.ulinkid = a.ulinkid and l.ctype='3' 
or route.uteamid=a.ulinkid and l.ctype='4' for xml auto ), '<k uid=', ',{uid:'), '/>', '}'),'ctitle=',
',ctitle:'),'cpicpath=',',cpicpath:'), 1, 1, '') )n) knowledge on knowledge.ulinkid=team.uid where team.ulineid=line.uid 
and team.cstatus='50' and line.cstatus='50' and team.dbgndate>'' and team.cissue in ('1','3') and 
line.cissue in ('1','3') and line.uid in (select distinct deptlink.ulinktableid from t_dept_link deptlink 
left join t_dept depta on depta.uid=deptlink.udeptid and deptlink.crange=0 left join t_user tusera on 
tusera.uid=deptlink.uuserid and deptlink.crange=2 left join t_role trole on trole.uid=deptlink.uroleid 
and deptlink.crange=3 left join t_dept deptb on (deptb.ccodepath like STUFF('%',1,0,depta.ccodepath) 
and deptlink.crange=0 or deptb.uid=deptlink.udeptid and deptlink.crange=1 or deptb.uid=tusera.udeptid 
and deptlink.crange=2 or deptb.uid=trole.udeptid and deptlink.crange=3) where deptlink.clinktable='t_line' 
and deptb.ccodepath like (select STUFF('%',1,0,ccodepath) from t_dept where uid='161BD0F3-9345-4543-A94D-73A4ED696A09'))
order by team.dbgndate 

t_line
t_team
t_team_route
t_picture
t_team_price
t_dept
t_dept_link
t_corp
t_user
t_role
t_member
t_customer
t_customergroup
t_customergroup_link
t_customergroup
t_customergroup_customer
t_theme
t_theme_link
t_tag
t_tag_link
t_knowledge
t_knowledge_link

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值