日期:2014-05-18 浏览次数:20638 次
declare @a table(a int ,b int,c int) insert into @a values(101,1,2002) insert into @a values(101,1,2003) insert into @a values(101,2,2004) insert into @a values(102,1,2002) insert into @a values(102,2,2003) select a,b,max(c)as 插入时间 from @a where b = 1 group by a,b
------解决方案--------------------
create table tb(a int,b int,c int) insert into tb select 101,1,2002 insert into tb select 101,1,2003 insert into tb select 101,2,2004 insert into tb select 102,1,2002 insert into tb select 102,2,2003 select * from (select * from tb where b=1) t where not exists( select 1 from tb where b=1 and a=t.a and c>t.c ) select a,b,max(c) from tb where b=1 group by a,b select * from tb t where c in(select max(c) from tb where a=t.a and b=1)
------解决方案--------------------
select t.* from tb t where b = 1 and 时间字段 = (select max(时间字段) from tb where b = 1 and a = t.a)
------解决方案--------------------
[Quote=引用:]
select t.* from tb t where b = 1 and 时间字段 = (select max(时间字段) from tb where b = 1 and a = t.a)