日期:2014-05-17 浏览次数:21004 次
with t as(
select '2012-05-20' data,12 id ,'aa' name from dual
union all select '2012-05-21',11,'bb' from dual
union all select '2012-05-22',13,'cc' from dual
union all select '2012-05-21',12,'bb' from dual
union all select '2012-05-22',12,'cc' from dual
)
select t1.* from (select t.* from t order by data desc,id) t1 where rownum<=3;
--建表和测试数据
create table test1
(
currentTime date,
id int
)
insert into test1 values(sysdate-233,1);
insert into test1 values(sysdate-23,2);
insert into test1 values(sysdate-33,3);
insert into test1 values(sysdate-133,4);
insert into test1 values(sysdate-73,5);
insert into test1 values(sysdate-93,6);
insert into test1 values(sysdate-53,7);
insert into test1 values(sysdate-43,8);
insert into test1 values(sysdate-143,9);
--查询方式1
select *from (
select * from test1 t order by t.currenttime desc) where rownum <=3 order by id
--查询结果1
2012-4-15 9:51:59 8
2012-4-25 9:51:58 3
2012-5-5 9:51:58 2
--查询方式2
2011-10-8 9:51:58 1
2012-1-6 10:06:49 9
2012-1-16 9:51:58 4
--查询结果2
2011-10-8 9:51:58 1
2012-1-6 10:06:49 9
2012-1-16 9:51:58 4
--你看你是需要哪种查询方式,至于显示在dataGridView中,你查询到数据了就和你平时方法一样
--ps:以后分别给这么少,太太太太太小气了!第一次看到5分的帖子。。