有时我们在做项目时,需要在SQL文里面对某个字段经过运算后再与一个常量比较:那么这将会对运行性能产生很大的影响:
请看下面SQL的执行效率:
select * from iroomtypeprice where amount/30< 100011
当改写成下面的SQL语句时效率明显提高了:
select * from iroomtypeprice where amount< 1000*30(<1
语句1因为要对没没条记录的字段amount做一个/的运算,所以必须进行全表扫描,表的合适索引不会起作用;而语句二就会用到表上的合适索引。因此效率明显提高。
 
另外,在where后面尽量少用substring等函数,这样也可以提高执行效率,如:
select * from iroomtypeprice where substring(card_no,1,4)='5378'(13)改成
select * from iroomtypeprice where card_no like '5378%'(<1)
 
select * from iroomtypeprice wher econvert(char(10),date,112)='19991201'10
select * from iroomtypeprice where date= '1999/12/01'< 1
 

相关文章:

  • 2022-02-13
  • 2022-02-28
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2021-06-07
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案