有个记录表 记录每天员工的打卡情况现在想SQL实现获取所有员工最后一次打卡的时间
(考虑不是所有员工都是最后一天打了卡,可能A员工最后一次是前几天打卡,那A的最后一次打卡就是前几天)
流水表 :员工姓名  打卡日期谢谢你的帮忙

解决方案 »

  1.   

    select *
    from tb a
    where not exists (select 1
        from tb b
        where b.employee=a.employee
        and b.processtime> a.processtime)
      

  2.   

    select
      *
    from
      tb t
    where
      processtime=(select max(processtime) from tb where employee=t.employee)
      

  3.   

    select 员工姓名 ,打卡日期=max(打卡日期)
    from tb 
    group by 员工姓名
    注意最好使用员工ID作为主键