日期:2014-05-18 浏览次数:20513 次
select a.* from a inner join (select rno,min(ye) from a group by rno) t on a.rno=t.rno
------解决方案--------------------
declare @tb table (rno varchar(10),rdate varchar(10),rtime varchar(5),ye int) insert into @tb select '001','2007-01-01','18:20',372 insert into @tb select '001','2007-01-01','20:20',370 insert into @tb select '001','2007-01-02','18:20',328 insert into @tb select '001','2007-01-03','08:20',312 insert into @tb select '002','2007-01-01','08:20',372 insert into @tb select '002','2007-01-01','20:20',368 insert into @tb select '002','2007-01-02','18:20',328 insert into @tb select '002','2007-01-03','08:20',312 insert into @tb select '003','2007-01-01','08:20',372 insert into @tb select '003','2007-01-01','20:20',366 insert into @tb select '003','2007-01-02','18:20',340 insert into @tb select '003','2007-01-03','08:20',312 select * from @tb a where not exists( select 1 from @tb where rno = a.rno and cast(rdate+' '+rtime as datetime)>cast(a.rdate+' '+a.rtime as datetime))
------解决方案--------------------
select t.* from tb where rdate = (select max(rdate) from tb where rno = t.rno) from tb t
------解决方案--------------------
select t.* from tb where ye = (select max(ye) from tb where rno = t.rno) from tb t