表1
職員番号 対象年月
0001 20071001
0001 20081101
0002 20060301
0002 20050401
0003 20050501
0003 20040401想取出毎个職員最大的対象年月結果:
職員番号 対象年月
0001 20081101
0002 20060301
0003 20050501
職員番号 対象年月
0001 20071001
0001 20081101
0002 20060301
0002 20050401
0003 20050501
0003 20040401想取出毎个職員最大的対象年月結果:
職員番号 対象年月
0001 20081101
0002 20060301
0003 20050501
http://topic.csdn.net/u/20080626/00/43d0d10c-28f1-418d-a05b-663880da278a.html
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 职员番号
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.对象年月)
(select max(([対象年月]) ) from 表1 a where a.职员番号=b.职员番号) as '對象年月'
from 表1 b order by b.职员番号
FROM TABLE1 CROSS JOIN
TABLE2
GROUP BY TABLE1.職員番号
不小心写错了,把你的当成两个表,
1.SELECT DISTINCT 職員番号, MAX(TABLE1.対象年月) AS 対象年月
FROM TABLE1
2.SELECT 職員番号, MAX(TABLE1.対象年月) AS 対象年月
FROM TABLE1 group by 職員番号