日期:2014-05-17 浏览次数:20426 次
--如果p_dt是个聚集索引的话,试试先利用一下
SELECT * from
(
SELECT * FROM pds_buy WHERE p_dt BETWEEN '1999-01-01' AND '2013-09-01'
)
where xxoo
SELECT * FROM pds_buy t1
WHERE p_dt BETWEEN '1999-01-01' AND '2013-09-01'
AND EXISTS(select 1 from pds_buy_product where t1.p_buyid=p_buyid AND p_id like '%33300%')
SELECT *
FROM pds_buy a
inner join (select distinct p_buyid from pds_buy_product where p_id like '%33300%') b
on a.p_buyid=b.p_buyid
WHERE a.p_dt BETWEEN '1999-01-01' AND '2013-09-01'
--#1.先缓存结果集2到表变量(有主键)
DECLARE @temp TABLE(p_buyid INT NOT NULL PRIMARY KEY)
INSERT @temp(p_buyid)
select distinct p_buyid from pds_buy_product where p_id like '%33300%'