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

请教 查询效率问题
SQL:
select   i.zinv_id,i.zinv_model,ib.zinv_brand_desc,ic.zinv_class_desc,s.zcost_price,s.zprice    
from   co.inv   i    
left   join   co.inv_class_barnd   icb   on   icb.zid   =   i.ZBRAND_CLASS_ID    
left   join   co.zinv_class   ic   on   ic.zinv_class_id   =   icb.zinv_class_id    
left   join   co.inv_brand   ib   on   ib.ZINV_BRAND_ID   =   icb.ZINV_BRAND_ID    
inner   join   (select   bd.zinv_id,isnull(ip.zcost_price,0)   zcost_price,isnull(bd.zprice,0)   zprice
from   bill.wm.bill_dtl   bd    
left   join   bill.wm.bill   b   on   b.zbill_id=bd.zbill_id   and   b.zcreat_dt   between   '2006-01-01 '   and   '2006-01-30 '    
left   join   pub_data.co.inv_price   ip   on   bd.zinv_id=ip.zinv_id   and   ip.zset_dt   between     '2006-01-01 '   and   '2006-01-30 '    
where   b.zbill_type_id=1   and   b.zbill_status_id=1        
group   by   bd.zinv_id   ,   ip.zcost_price,bd.zprice
having   min(isnull(ip.zcost_price,0))> min(isnull(bd.zprice,0)))   s   on   s.zinv_id   =   i.zinv_id
  where   i.zstop_yn <> 1  

查询效率的问题:
co.inv   产品表
co.inv_class_barnd   类别品牌中转表
co.zinv_class   产品类别表
co.inv_brand     产品品牌表
bill.wm.bill_dtl   单据体表
bill.wm.bill   单据头表
co.inv_price   产品价格表

select   bd.zinv_id,isnull(ip.zcost_price,0)   zcost_price,isnull(bd.zprice,0)   zprice
from   bill.wm.bill_dtl   bd    
left   join   bill.wm.bill   b   on   b.zbill_id=bd.zbill_id   and   b.zcreat_dt   between   '2006-01-01 '   and   '2006-01-30 '    
left   join   pub_data.co.inv_price   ip   on   bd.zinv_id=ip.zinv_id   and   ip.zset_dt   between     '2006-01-01 '   and   '2006-01-30 '    
where   b.zbill_type_id=1   and   b.zbill_status_id=1        
group   by   bd.zinv_id   ,   ip.zcost_price,bd.zprice
having   min(isnull(ip.zcost_price,0))> min(isnull(bd.zprice,0))  
查出产品报价大于单据体(销售出去的价格)的产品信息   (包含   产品id,报价,销售价)

现在这个sql的数据出来没有问题   不过就是很慢   有没有别的写法提高效率??
在页面上使用数据绑定控件会超时(asp.net)

------解决方案--------------------
暈,幫頂吧.
------解决方案--------------------
看着都累
------解决方案--------------------
多大的数据量?考虑用分页吧
------解决方案--------------------
好大一堆啊

试试 临时表 将步骤不解开了 不会超时
------解决方案--------------------
ajax can not reduce sql query time