在表TABLE中
char      char   char    char 
管理番号  输送no  出门时间 入门时间
001      0001
001      0002
管理番号和输送no为主键
现在要检索满足条件的管理番号
检索条件如下:
1.输送no + 入门时间为空
2.输送no + 出门时间不为空
同时满足条件1.2的管理番号
请问高手sql文怎么写?急!!!

解决方案 »

  1.   

    select *
    from table
    where 输送no=
    and   出门时间  is not null
    and   入门时间  is null 
      

  2.   

    sorry!!发错了重发一边!在表TABLE中 
    char      char   char    char  
    管理番号  输送no  出门时间 入门时间 
    001      0001 
    001      0002 
    管理番号和输送no为主键 字段全为char型
    现在要检索满足条件的管理番号 
    检索条件如下: 
    1.输送no + 入门时间为空 
    2.输送no-1 + 出门时间不为空 
    同时满足条件1.2的管理番号 
    请问高手sql文怎么写?急!!!
      

  3.   

    select distinct t1.管理番号 from TABLE t1,TABLE t2
    where t1.管理番号=t2.管理番号
      and to_number(t1.输送no)=to_number(t2.输送no)-1
      and t1.入门时间 is null and t2.出门时间 is not null
      

  4.   

    select * 
    from tbname a
    where 输送no= 'xxx'
    and   出门时间  is not null
    and exists(select 1 from tbname b where b.no=lpad(a.no-1,4,'0') and  入门时间  is null )
      

  5.   

    楼上的朋友您好,我现在的用的数据库是DB2,不知道您写的SQL文影不影响
    还有就是您能不能解释一下lpad()这个函数的作用是什么? 谢谢!!
      

  6.   

    lpad:用指定的字符从左边补齐到规定的长度
      

  7.   


    where 输送no= 'xxx' ???