现在的位置: 首页 > 综合 > 正文

sql查询总结

2012年04月16日 ⁄ 综合 ⁄ 共 423字 ⁄ 字号 评论关闭

 

以下的运行起来得4个多小时
1 SET STATISTICS IO ON 
2 select pkid 
3 from et_order  
4 where pay_type = 4 and status = 20 and pkid not in (select isnull(get_orderid,0from score_Get)

 

 

以下运行起来就几秒钟

 

代码

1 Create Table #T
2 (
3     get_orderid int
4 )
5 
6 insert into #T select isnull(get_orderid,0from score_Get
7 
8 select pkid from et_order  where pay_type = 4 and status = 20 and pkid not in (select * from #T)

 

 

 

总结:

 

    要把数据库语句写的尽量简单,这样它的运行效率会快很多

抱歉!评论已关闭.