我要做一个视图,要把所有记录中,每个keyid对应的created日期最大的记录筛选出来形成一个视图。
表内没有唯一的值。
下面是表结构。。谢喽,各位。。    KEYID NAME STATUS TYPE CREATED
1 3363 200101001 10 2011/2/26 23:31:06
21 3363 east 200101001 10 2011/3/8 15:02:38
58 3364 north 200101001 10 2011/3/8 15:02:37
18 3363 north 200101001 10 2011/3/8 14:59:23
26 3363 south 200101001 10 2011/3/8 15:02:39
42 3363 west 200101001 10 2011/3/8 15:02:39
6 3365 west 200101001 10 2011/3/8 15:02:38
61 3365 east 200101001 11 2011/3/8 15:02:38
65 3364 east 200101002 11 2011/3/8 15:02:38
35 3363 north 200101001 11 2011/3/8 15:02:37

解决方案 »

  1.   

    create or replace view created_view as select keyid,max(create) max_created from biao_name group by keyid   随便写了个  试试吧!
      

  2.   

    SELECT *
      FROM table1 a
     WHERE NOT EXISTS (SELECT 1
              FROM table1 b
             WHERE a.keyid = b.keyid
               AND a.created < b.created);
      

  3.   

    select t.* from tb t where CREATED = (select max(CREATED) from tb where keyid = t.keyid)select t.* from tb t where not exists (select 1 from tb where keyid = t.keyid and CREATED > t.CREATED)
      

  4.   

    create or replace view v_test as 
    select  keyid,max(create) from talbe group by keyid
      

  5.   

    谢谢大家~一下收到这么多条,呵呵 一直对group by的用法很晕,还要好好研究下。。