除了添加索引 我加了索引反而变慢了呢 添加索引数据还容易不准确;with AA as (select * from ( select *,ROW_NUMBER() over(partition by product_code order by s_date desc ) t1,replace(replace(replace(convert(varchar,s_date,102),'-',''),':',''),' ','') as 开始时间,replace(replace(replace(convert(varchar,e_date,102),'-',''),':',''),' ','') as 结束时间 from DW_XGTB where brand in ('芭欧/BOOL','芭欧','薇薇卡','薇薇卡/VIVICA&CO.','VY','薇娅(VIYA)','薇娅')) t2 where t2.t1<=4 and platform is not null),BB AS ( select DesignKCode,ExtStr1,BM ,PP from DW_BoolProductsFile ),CC as (SELECT BB.DESIGNKCODE,AA.product_code,AA.brand,(CAST(开始时间 as varchar(20))+'-'+CAST(结束时间 as varchar(20))) 活动时间,result_Y,AA. platform,AA.shop_namefrom AA left join BB ON AA.brand=BB.PP and AA.product_code=BB.BM or AA.product_code=BB.EXTSTR1 ),DD AS ( select DISTINCT * from CC where DesignKCode is not null) select * from ( select * ,row_number() over(partition by designkcode order by DD.活动时间 desc) r from DD) DD where DD.r<=4