我要查询一个表中的记录,比如说student
student
   no  name  age  flag date_login_begin   date_login_end  
   1    Jim   20   1     2005/05/06         2005/04/09
   2    Tom   20   0
   3    Jeric 20   0
   4    Ray   20   1     2006/02/05          2006/04/25        
  现在我要把flag为1 日期在2006/02/05与2006/04/25 之间的记录找出来
 并且还要查出age为20且flag为0的记录查出来,
 
请问各位大侠这怎么写SQL

解决方案 »

  1.   

    select * from student where flag=1 and to_char(flag date_login_begin,'YYYYMMDD') >20060205 and 
     to_char(date_login_begin,'YYYYMMDD')<20060405 
    union 
    select * from     where flag=0 and age=20
      

  2.   

    select * from student where flag=1 and to_char(date_login_begin,'yyyymmdd') between '20060205' and '20060425'
    union 
    select * from  student where flag=0 and age=20
      

  3.   

    用or方便一些吧,引用一下前面两位的一些东西:select * from student where ( flag=1 and to_char(flag date_login_begin,'YYYYMMDD') >20060205 and 
     to_char(date_login_begin,'YYYYMMDD')<20060405 ) or ( flag=0 and age=20 )