日期:2014-05-17 浏览次数:20662 次
declare @T table (a int,b int,c int,d int)
insert into @T
select 8,4,11,1 union all
select 8,4,11,6 union all
select 8,4,11,5 union all
select 8,4,11,3 union all
select 8,4,11,4 union all
select 8,4,11,2 union all
select 8,4,11,1 union all
select 8,4,12,1 union all
select 8,4,12,5 union all
select 8,4,12,5 union all
select 8,4,13,1
select * from
(
select * from @T t
where d=(select max(d) from @T where a=t.a and b=t.b and c=t.c)
) a
group by a,b,c,d having(count(1)=1)
--> 测试数据: @T
declare @T table (a int,b int,c int,d int)
insert into @T
select 8,4,11,1 union all
select 8,4,11,6 union all
select 8,4,11,5 union all
select 8,4,11,3 union all
select 8,4,11,4 union all
select 8,4,11,2 union all
select 8,4,11,1 union all
select 8,4,12,1 union all
select 8,4,12,5 union all
select 8,4,12,5 union all
select 8,4,13,1
;with maco as
(
select * from @T t
where d=(select max(d) from @T where a=t.a and b=t.b and c=t.c)
)
select * from maco
group by a,b,c,d having(count(1)=1)
/*
a b c d
----------- ----------- ----------- -----------
8 4 11 6
8 4 13 1
*/