select * from (select * from test1 order by pl desc) where rownum=2;
这个意思么?
这个意思么?
解决方案 »
- 主键、唯一约束问题
- oracle 与 corba
- PL/SQL登录问题?
- 请教,急急!!!!!
- 超简单的问题,但请回答准确答案,并说明理由!!在线等
- 急请教高手:ASP连接ORACLE8.17的问题
- 关于10g触发器中:new 和 :old 的用法问题?? 大侠请进,分不够再加!!
- select的用法,怎么写这段sql文
- ***************SQL语句执行次序问题***************
- 有关日期!!!
- 请问,我有个表的主键能不能在插入的时候自动生成值,用户不需要填写,如果可以请问怎么写CREATE TABLE的SQL
- lunix上对oracle的基本操作及SQL语法,哪里有下载?
这样呢?
(select * from test1 order by id desc,p1 desc) where rownum <= 2
minus
select * from
(select * from test1 order by id desc,p1 desc) where rownum <= 1
即将id和p1的值union all成一个字段后安desc排序后的第二条纪录为第二大值。
参与者肯定有分
select * from (select id,pl from test1 group by id,pl order by id, pl desc) where rownum <= 2;
“即将id和p1的值union all成一个字段后安desc排序后的第二条纪录为第二大值。”
这样试试。
--------- ---------
1 2
1 3
4 3
2 4
4 5SQL> select decode(sign(max(bbb)-max(ccc)),1,max(ccc),max(bbb)) second from a5; SECOND
---------
4
max(id)在id和p1所有的值中有可能只是第8大或。。,所以你的SQL肯定不行。
不过非常感谢。
select aaa from (
select id aaa from test1
union all
select pl aaa from test1)order by aaa desc) where rownum<3
minus
select aaa from (
select id from (
select pl aaa from test1
union all
select ccc aaa from test1)order by aaa desc) where rownum<2;
这样一般没问题
select aaa from (
上面有点笔误
select id aaa from test1
union all
select pl aaa from test1)order by aaa desc) where rownum<3
minus
select aaa from (
select aaa from (
select pl aaa from test1
union all
select ccc aaa from test1)order by aaa desc) where rownum<2;
--------- ---------
1 2
1 3
4 3
2 4
4 5SQL> select aaa from (
2 select aaa from (
3 select bbb aaa from a5
4 union all
5 select ccc aaa from a5)order by aaa desc) where rownum<3
6 minus
7 select aaa from (
8 select aaa from (
9 select bbb aaa from a5
10 union all
11 select ccc aaa from a5)order by aaa desc) where rownum<2; AAA
---------
4
select id from
(select id id from test1 union select pl id from test1 ) order by id desc)
where rownum <= 2;