假如有个表
学号  姓名 年龄
...   ...  ...
我做一个查询 select * from 表 where 年龄 < 30
得到一批记录,我想在这个结果上再做一个查询,查出学号 > 1001的记录
在前一个查询的基础上再做查询,该怎么做?
请高手指点   非常感谢!

解决方案 »

  1.   

    select * from (select * from 表 where 年龄 < 30) where 学号 > 1001
      

  2.   

    select * from 表 where 年龄<30 and 学号>1001
      

  3.   

    select * from (select * from 表 where 年龄 < 30) where 学号 > 1001
      

  4.   

    select * from (select * from 表 where 年龄 < 30) where 学号 > 1001
    这样子做的话,还是要经过:select * from 表 where 年龄 < 30 这个步骤,效率上没有提高!我的意思就是要省掉这一步!既然查过了,就不要再查一次。是不是要用到临时表?或者
    什么存储过程之类的?
      

  5.   

    假设一下:这个表有几十万条记录,做了一个查询:select * from 表 where 年龄 < 30,对
    这个结果要求更精细点,在这个基础上再有条件的查询。如果是这样写:
    select * from (select * from 表 where 年龄 < 30) where 学号 > 1001,很明显,这个效率是很低的。那还不如直接 select * from 表 where 年龄 < 30 and 学号 > 1001 
    应该是有办法在这个结果的基础上做查询的,请大家指点
      

  6.   

    select * from (select * from 表 where 年龄 < 30) where 学号 > 1001