34,593
社区成员
发帖
与我相关
我的任务
分享
declare @table table (A int,B int,C int)
insert into @table
select 1,2,1 union all
select 2,3,1 UNION ALL
SELECT 2,3,2 UNION ALL
SELECT 2,1,2
SELECT aa.a,aa.b,MIN(c) AS c FROM (
select * from @table t where b=
(select max(b) from @table where A=t.A)
) aa GROUP BY aa.a,aa.b order by aa.a
declare @table table (A int,B int,C int)
insert into @table
select 1,2,1 union all
select 2,3,1 UNION ALL
SELECT 2,2,2
select * from @table t where b=
(select max(b) from @table where A=t.A) order by a
/*
A B C
----------- ----------- -----------
1 2 1
2 3 1
*/
declare @table table (A int,B varchar(7),C int)
insert into @table
select 1,'2009-06',1 union all
select 2,'2009-06',2 union all
select 2,'2009-07',3 union all
select 3,'2009-06',2
select * from @table t where b=
(select max(b) from @table where A=t.A) order by a
/*
A B C
----------- ------- -----------
1 2009-06 1
2 2009-07 3
3 2009-06 2
*/