表1
職員番号     対象年月
0001        20071001
0001        20081101
0002        20060301
0002        20050401
0003        20050501
0003        20040401想取出毎个職員最大的対象年月結果:
職員番号     対象年月
0001        20081101
0002        20060301
0003        20050501

解决方案 »

  1.   

    select * from t1 a where not exists(select 1 from t1 where [職員番号]=a.[職員番号] and [対象年月]>a.[対象年月])
      

  2.   

    其它方法參照:
    http://topic.csdn.net/u/20080626/00/43d0d10c-28f1-418d-a05b-663880da278a.html
      

  3.   

    select * from 表1 a where not exists(select 1 from 表1 b where a.職員番号=b.職員番号 and a.対象年月<b.対象年月)
      

  4.   

    select * from tb a where not exists(select * from tb where a.职员编号=职员编号 and 对象年月>a.对象年月)
      

  5.   

    select [職員番号],MAX([対象年月]) AS [対象年月] FROM T GROUP BY [職員番号]
      

  6.   

    select [職員番号],MAX([対象年月]) AS [対象年月] FROM T GROUP BY [職員番号]
      

  7.   


    if object_id('表1') is not null
       drop table 表1
    go
    create table 表1
    ( 职员番号 int,
      对象年月 int
    )
    insert into 表1 select 0001,20071001
        union all   select 0001,20081101
        union all   select 0002,20060301
        union all   select 0002,20050401
        union all   select 0003,20050401
        union all   select 0003,20040401
    select 职员番号, max(对象年月) from 表1 group by 职员番号
      

  8.   


    if object_id('表1') is not null
       drop table 表1
    go
    create table 表1
    ( 职员番号 int,
      对象年月 int
    )
    insert into 表1 select 0001,20071001
        union all   select 0001,20081101
        union all   select 0002,20060301
        union all   select 0002,20050401
        union all   select 0003,20050401
        union all   select 0003,20040401
    -----------
    select * from 表1 a where   exists(select 1 from 表1 where 职员番号=a.职员番号
    and 对象年月<a.对象年月)
      

  9.   

    select distinct  职员番号,
           (select max(([対象年月]) ) from 表1 a  where a.职员番号=b.职员番号) as '對象年月'
    from 表1 b  order by b.职员番号
      

  10.   

    select 职员番号,max(对象年月) from 表1 group by 职员番号
      

  11.   

    SELECT DISTINCT TABLE1.職員番号, MAX(TABLE1.対象年月) AS 対象年月
    FROM TABLE1 CROSS JOIN
          TABLE2
    GROUP BY TABLE1.職員番号
      

  12.   

    select 职员番号,max(对象年月) 对象年月 from 表1 group by 职员番号
      

  13.   


    不小心写错了,把你的当成两个表,
    1.SELECT DISTINCT 職員番号, MAX(TABLE1.対象年月) AS 対象年月
    FROM TABLE1
    2.SELECT 職員番号, MAX(TABLE1.対象年月) AS 対象年月
    FROM TABLE1 group by 職員番号