有没有办法最小化此SQL查询

时间:2014-12-18 12:09:17

标签: sql sql-server

有没有办法最小化这个SQL查询

delete from [empDetail] 
where empDetailID in
         (select empDetailID 
          from 
              (select * 
               from [empDetail] 
               where ItemID in 
                        (select ItemID 
                         from [empDetail] 
                         where QuoteID in 
                                  (select QuoteID 
                                   from [emp] 
                                   where Title = 'Remark' and UserID = 12345)
                         group by ItemID
                         having COUNT(ItemID) > 1) 
              ) a
          where empSelectionID in (2,3,4,5)
      );

1 个答案:

答案 0 :(得分:1)

这可能有效,

delete * from [empDetail]  as b
inner join [emp]  as a on a.QuoteID  = b.QuoteID 
where Title = 'Remark' and UserID = 12345
and empSelectionID in (2,3,4,5)
group by b.ItemID
having COUNT(ItemID) > 1