SQL> desc test;
 名称                                      空?      类型
 ----------------------------------------- -------- -------------------- D                                                  DATE
 NO                                                 CHAR(3)
 Q                                                  NUMBER(38)SQL> select * from test;
14-7月 -05 001          5
15-7月 -05 001          6
16-7月 -05 001          7
17-7月 -05 001          7
18-7月 -05 001          7
17-7月 -05 002          6
13-7月 -05 003          3
14-7月 -05 003          4
15-7月 -05 003          4
16-7月 -05 003          4
17-7月 -05 003          5
18-7月 -05 003          5已选择12行。SQL> select to_char(min(a.d),'yyyy/mm/dd') "date",b.no,b.q
  2  from test a,
  3  (select no,max(q) q from test group by no) b
  4  where a.no=b.no and a.q=b.q
  5  group by b.no,b.q;
2005/07/16 001          7
2005/07/17 002          6
2005/07/17 003          5

解决方案 »

  1.   

    最后一次变更,是不是指最近更新?Q应该不一定后一次更新就比前一次大吧
    那楼上的sql:select no,max(q) q from test group by no,取的是最大Q对应的更新时间select no,max(date) from test group by no
      

  2.   

    用分析函数select to_char(min(a.d),'yyyy/mm/dd') "date",b.no,b.q
    from (select *,row_number() over(partition by no order by date desc) r from test)
    where r=1
      

  3.   

    SQL> select to_char(date1,'yyyy/mm/dd') "date",no,q from (
      2  select t.*,row_number() over(partition by no,q order by date1) rn,
      3         dense_rank() over(partition by no order by q desc) dr
      4  from test1 t
      5  ) where rn = 1 and dr = 1
      6  /date       NO           Q
    ---------- --- ----------
    2005/07/16 001          7
    2005/07/17 002          6
    2005/07/17 003          5已用时间:  00: 00: 00.00
      

  4.   

    要是最后更新的记录,并不一定日期最大,也不一定Q最大,可以
    select b.* from test b,
    (select NO,max(rowid)seq from test group by NO)a
    where b.rowid = a.seq
    and b.NO= a.NO