建立一个表,名称为 info表的内容:人员姓名      做事的顺序       做了的事情       做每件事的时间()等等其他字段。。
  name          order             thing           time        ............
   A              1                t1             01:35         .............
   A              2                t2             05:20          ...........
   A              3                t3             .....         ............
   A              4                t4             .....          .........
  
   B              1                t4             ......           ...........
   B              2                t2             .....            .........
   B              3                t1             ......            ..........   C              1                t4             ......            ..........
   
   D              1                t3            ......             .........
   D              2                t1             .....              .........现在的问题是,要求过滤出人员的姓名,要求是 这个人必须把事情 t1 和 t4 都做了,而且他做事情的顺序还必须是先做的 t1 然后再做的 t4 , 从上面的表中可以看出人员 A 就是符合要求的,那么,
请问能用什么方法把其过滤出? 望赐教!

解决方案 »

  1.   

    想通过一条SQL语句实现可能有些困难,可以自己写作个存储过程,通过游标来处理。
      

  2.   

    select t1.name from 
    (select name, [order]
    from info 
    where thing='t1'
    group by name, [order]) t1,
    (select name, [order]
    from info 
    where thing='t4'
    group by name, [order]) t2
    where t1.[order]<t2.[order] and t1.name=t2.name
    group by t1.name
      

  3.   

    select * from info if1, info if2
    where if1.name=if2.name and (if1.thing=t1 and if2.thing=t4) and if1.time<if2.time
      

  4.   

    那如果我表里面的order内容是order
      第1件
      第2件
      第3件
      第4件
      第5件
    它不是直接给的数字,SQL有简单函数可以直接取出其中数字再进行比较吗?
      

  5.   

    第1件
      第2件
      第3件
      第4件
      第5件这些是可以在sql里比较的,第1件<第2件
      

  6.   

    不会吧,我还以为是要T1->T4都要按顺序来呢。晕