select * from a where date_a =(select max(date_a ) from a)
select * from a where date_a=(select max(date_a) from a where to_char(date_a,'yyyymmdd')<=to_char(sysdate,'yyyymmdd'));是这个意思吗?
用rownum = 1 例如: select * from table where .... and rownum = 1
select * from table having rownum = max(rownum)
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 * from table having rownum = max(rownum)是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢, MSSQL这方面要比ORACLE好很多
如果使用rownum,则使用以下语句即可: select * from (select * from table order by date desc) where rownum=1;
select * from table_a where rownum<10 最后where rownum代替top
例如:
select * from table
where ....
and rownum = 1
having rownum = max(rownum)
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
having rownum = max(rownum)是可以取最大的一个,但我是取最大的N(N>1)条那该怎么写呢,
MSSQL这方面要比ORACLE好很多
select * from (select * from table order by date desc) where rownum=1;
最后where rownum代替top