select name,age,sex from A where key in('1','2','3','4','5','6','7','8'),这种语句执行效率比较慢,请教高手如何优化这条语句,提高执行效率!谢谢!

解决方案 »

  1.   

    select name,age,sex from A where key in('1','2','3','4','5','6','7','8'),加个索引
      

  2.   


    转化成连接 try:
    select name,age,sex from a ,master..spt_values m where a.[key]=m.number and m.type='p' and number between 1 and 8
      

  3.   

    select [name],age,sex from A a,
    (select 1 as [key] union select 2
                  union select 3
                  union select 4
                  union select 5
                  union select 6
                  union select 7 
                  union select 8
                  union select 9)b
    where a.[key]=b.[key]
      

  4.   

    select 
        [name],age,sex from A a,
        (select 1 as [key] 
                  union select 2
                  union select 3
                  union select 4
                  union select 5
                  union select 6
                  union select 7 
                  union select 8
                  union select 9)b
    where 
       a.[key]=b.[key]转换为union 然后在KEY字段加索引