select  b.groupid,b.groupname,a.name,a.alarm from a,b where a.goupid=b.groupid and a.time in (select max(time) from a where alarm=1 group by groupid)

解决方案 »

  1.   

    看来是个考勤的,抓那个最晚的,还有警告标志! 日!
    小写一把哈:
    ----------
    select a.groupid, b.groupname, a.name, a.alarm
    from (select groupid, max(time) time from a where alarm = 1 group by groupid) t1, a, b
    where a.groupid = t1.groupid and  b.groupid = t1.groupid and a.time = t1.time and a.alarm = 1
    ----------
      

  2.   

    fjmingyang(努力升级) 写的不对!
    要是有好几个人,都来的最晚,时间也一样,但是有的有警告标志,有的没有警告标志怎么办?
      

  3.   

    操,我写的也有点问题,改一下啊
    select a.groupid, b.groupname, a.name, a.alarm
    from (select groupid, max(time) time from a where alarm = 1 group by groupid) t1, a, b
    where a.groupid = t1.groupid and  b.groupid = a.groupid and a.time = t1.time and a.alarm = 1
      

  4.   


    select a1.groupid,b1.groupName,a1.name,a1.alarm from table_a a1,table_b b1
     (select groupid,max(time) as time from table_a group by groupid) max1
     where a1.groupid = max1.groupid
     and a1.time = max1.time
     and a1.alarm = 1
     and b1.groupid = a1.groupid
      

  5.   

    select b.Groupid,b.GroupName,min(a.name),min(a.alarm)
    from a,b
    where a.Groupid=b.Groupid
    group by b.Groupid,b.GroupName