改写成left join联合查询

CaRrot_Love 2014-08-08 02:29:10
select * from M_News where countryID in ( select id from U_LanguageCategory where ParentID=2 and (id in ((select UHometown from U_Caricature where UID=8), (select HometownID from areas where id in ((select GoCityID from U_Caricature where UID=8),(select UCity from U_Caricature where UID=8)) ))))

坐等大手
...全文
112 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
shoppo0505 2014-08-08
  • 打赏
  • 举报
回复
不清楚具体表格的关系,直接改写了一下,试试能不能行。 ;with Data_U_Caricature as ( SELECT GoCityID , UCity , UHometown FROM U_Caricature WHERE UID = 8 ) , Data_Areas as ( select HometownID from areas inner join Data_U_Caricature a on a.GoCityID = areas.id union select HometownID from areas inner join Data_U_Caricature b on a.UCity = areas.id ) , Data_U_LanguageCategory AS ( select id from U_LanguageCategory inner join Data_U_Caricature a on a.UHometown = U_LanguageCategory.id where ParentID = 2 union select id from U_LanguageCategory inner join Data_Areas a on a.HometownID = U_LanguageCategory.id where ParentID = 2 ) select * from M_News inner join Data_U_LanguageCategory on M_News.id = Data_U_LanguageCategory.id

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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