sql查询总结
以下的运行起来得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,0) from score_Get)
2 select pkid
3 from et_order
4 where pay_type = 4 and status = 20 and pkid not in (select isnull(get_orderid,0) from score_Get)
以下运行起来就几秒钟
代码
1 Create Table #T
2 (
3 get_orderid int
4 )
5
6 insert into #T select isnull(get_orderid,0) from score_Get
7
8 select pkid from et_order where pay_type = 4 and status = 20 and pkid not in (select * from #T)
2 (
3 get_orderid int
4 )
5
6 insert into #T select isnull(get_orderid,0) from score_Get
7
8 select pkid from et_order where pay_type = 4 and status = 20 and pkid not in (select * from #T)
总结:
要把数据库语句写的尽量简单,这样它的运行效率会快很多