日期:2014-05-18  浏览次数:20474 次

这样的子查询有没有办法简化?
SELECT   MasterChannel_ID,   Channel_ID,   c_Name   FROM   Sys_Channel   WHERE   MasterChannel_ID   =  
(SELECT   MasterChannel_ID   FROM   Sys_Channel   WHERE   Channel_ID   =
(SELECT   Channel_ID   FROM   Sys_ChannelColumn   WHERE   Column_ID   =  
(SELECT   TOP   1   VerticalChannel_ID   FROM   Sys_ChannelAndProduct   WHERE   Product_ID   =   14019)
))
AND Recycle   =   0

------解决方案--------------------
改成表关联应该效率会好一些吧
没有测试过

SELECT a.MasterChannel_ID, a.Channel_ID, a.c_Name
FROM Sys_Channel a , Sys_Channel b , Sys_ChannelColumn c ,
(SELECT TOP 1 VerticalChannel_ID FROM Sys_ChannelAndProduct WHERE Product_ID = 14019) d
where a.MasterChannel_ID = b.MasterChannel_ID and b.MasterChannel_ID = c.Channel_ID
and c.Column_ID = d.VerticalChannel_ID and a.Recycle = 0