select tid,opst from 
(select tid,opst,rank() over(partition by sqid order by recordtime desc) rk
from s ) t where rk=1;

解决方案 »

  1.   

    select * from s where tid in (select tid from s group by spid having recordtime=max(recordtime))
      

  2.   

    select * from table_name t where t.tid in (select tid,max(recordtime) from table_name group by tid,recordtime)
      

  3.   

    select *
    from s,
         (select sqid,max(recordtime) recordtime
          from s
          group by sqid) t1
    where s.sqid = t1.sqid
    and   s.recordtime = t1.recordtime
      

  4.   

    select a.recordtime,sqid,opst 
      from s a
     where a.sqid = '1155' and
           a.recordtime = (select b.max(recordtime)
                             from s b
                            where a.sqid = b.sqid) ;
      

  5.   

    1、select a.tid,sqid,opst,a.recordtime 
      from s a
     where a.sqid = '1155' and
           a.recordtime = (select max(recordtime)
                             from s b
                            where a.sqid = b.sqid) 2、select *
    from s,
         (select sqid,max(recordtime) recordtime
          from s
          group by sqid) t1
    where s.sqid = t1.sqid
    and   s.recordtime = t1.recordtime
      

  6.   

    使用first_value分析函数进行处理即可.
    select distinct tid,sqid,
        first_value(opst) over(partition by sqid order by recordtime desc) opst,
        first_value(recordtime) over (partition by sqid order by recordtime desc) record_time
    from tbl;
      

  7.   

    用分析函数
    select tid,opst from 
    (select tid,opst,rank() over(partition by sqid order by recordtime desc) aa
    from s ) t where aa=1;
      

  8.   

    select tid,opst from 
    (select tid,opst,rank() over(partition by sqid order by recordtime desc) aa
    from s ) t where aa=1;
      

  9.   

    看来bzszp(SongZip)比较喜欢用分析函数,我比较喜欢传统方式,可能是因为我经常要和oracle早期版本打交道。select tid, sqid, opst, recordtime
      from mytable x
     where recordtime in (select max (recordtime)
                            from mytable
                           where sqid = x.sqid)
       and sqid = 1155;