select gh,name,min(time) as first_time,max(time) as end_time from test group by gh,name

解决方案 »

  1.   

    为什么要把name放到这个表里面?
      

  2.   

    name和gh有区别么?这是一个刷卡机啊,不放name的话也可以,但是gh不还是要处理的么
      

  3.   

    呵呵,原来是读卡机,那也没什么。
    主要我觉得name是会重复,sql就有问题了
      

  4.   

    select DISTINCT test1.gh as 工号, test1.name as 姓名,
    (select min(test2.time) 
     from test as test2
     where test1.name = test2.name) as 起始时间,
    (select max(test3.[time])
     from test as test3
     where test3.name = test1.name) as 结束时间
    from test as test1--------------------------------------------------------
    这样应该是你要的结果,我试过了,应该没问题
      

  5.   

    各位大哥,我看不懂这个SQL语句,我想学,有没有好书或好的网站介绍。