就是从复合条件的记录中过滤出
距离当前日期最近的(最新的)一条记录,
我试过top关键字,但oracle中好像没有这个关键字,
请各位大侠帮小弟一下,万分感谢!
11 个解决方案
#1
select * from a where date_a =(select max(date_a ) from a)
#2
就是楼上所说的。
#3
距离当前最近和最新是什么意思?。假设当前日期是2006-05-13,一个日期为2006-05-14,一个为2006-05-23,该取哪个?语文学的不太好。。。。
#4
select * from a where date_a=(select max(date_a) from a where to_char(date_a,'yyyymmdd')<=to_char(sysdate,'yyyymmdd'));
是这个意思吗?
是这个意思吗?
#5
ly43779660(Zh) 可以
#6
用rownum = 1
例如:
select * from table
where ....
and rownum = 1
例如:
select * from table
where ....
and rownum = 1
#7
select * from table
having rownum = max(rownum)
having rownum = max(rownum)
#8
lyq_lawrance(lawrance) 的效率太低,
Select id
From table a,
(select id,max(date) As date
from table
where Date Between Pi_Startdate And Pi_Enddate
group by id) b
where a.id=b.id and
a.date =b.date
Select id
From table a,
(select id,max(date) As date
from table
where Date Between Pi_Startdate And Pi_Enddate
group by id) b
where a.id=b.id and
a.date =b.date
#9
select * from table
having rownum = max(rownum)
是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢,
MSSQL这方面要比ORACLE好很多
having rownum = max(rownum)
是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢,
MSSQL这方面要比ORACLE好很多
#10
如果使用rownum,则使用以下语句即可:
select * from (select * from table order by date desc) where rownum=1;
select * from (select * from table order by date desc) where rownum=1;
#11
select * from table_a where rownum<10
最后where rownum代替top
最后where rownum代替top
#1
select * from a where date_a =(select max(date_a ) from a)
#2
就是楼上所说的。
#3
距离当前最近和最新是什么意思?。假设当前日期是2006-05-13,一个日期为2006-05-14,一个为2006-05-23,该取哪个?语文学的不太好。。。。
#4
select * from a where date_a=(select max(date_a) from a where to_char(date_a,'yyyymmdd')<=to_char(sysdate,'yyyymmdd'));
是这个意思吗?
是这个意思吗?
#5
ly43779660(Zh) 可以
#6
用rownum = 1
例如:
select * from table
where ....
and rownum = 1
例如:
select * from table
where ....
and rownum = 1
#7
select * from table
having rownum = max(rownum)
having rownum = max(rownum)
#8
lyq_lawrance(lawrance) 的效率太低,
Select id
From table a,
(select id,max(date) As date
from table
where Date Between Pi_Startdate And Pi_Enddate
group by id) b
where a.id=b.id and
a.date =b.date
Select id
From table a,
(select id,max(date) As date
from table
where Date Between Pi_Startdate And Pi_Enddate
group by id) b
where a.id=b.id and
a.date =b.date
#9
select * from table
having rownum = max(rownum)
是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢,
MSSQL这方面要比ORACLE好很多
having rownum = max(rownum)
是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢,
MSSQL这方面要比ORACLE好很多
#10
如果使用rownum,则使用以下语句即可:
select * from (select * from table order by date desc) where rownum=1;
select * from (select * from table order by date desc) where rownum=1;
#11
select * from table_a where rownum<10
最后where rownum代替top
最后where rownum代替top