悬赏,一个SQL语句如何拼写。(肯定接贴)

zhaoyongzhu 2002-08-22 12:15:53
表结构为:
SQL> select * from test1;

ID ZYZ1 P1 DOCTIME
---------- ---------- ---------- ----------
1 dfdf 2
1 2 01-5ÔÂ -02
1 2 20-8ÔÂ -02
1 df0 2


求id和p1的第二大值,即将id和p1安desc排序后的第二条纪录为第二大值。
在上面的数据中求出的第二大值应该为2
...全文
42 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
javafish 2002-08-22
  • 打赏
  • 举报
回复
如果你的id和pl是一一对应的话还可以理解,要不就不懂了
select * from (select id,pl from test1 group by id,pl order by id, pl desc) where rownum <= 2;
zhaoyongzhu 2002-08-22
  • 打赏
  • 举报
回复
sorry是我没说清,希望大家继续努力。多谢了。
参与者肯定有分
zhaoyongzhu 2002-08-22
  • 打赏
  • 举报
回复
我是求id和p1的第二大值.
即将id和p1的值union all成一个字段后安desc排序后的第二条纪录为第二大值。
zcs_1 2002-08-22
  • 打赏
  • 举报
回复
select * from
(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
duckcn 2002-08-22
  • 打赏
  • 举报
回复
select * from (select * from test1 order by id, pl desc) where rownum=2;
bzszp 2002-08-22
  • 打赏
  • 举报
回复
select ID,ZYZ1,P1, DOCTIME from (select rownum id,ID,ZYZ1,P1, DOCTIME from test1 order by pl desc) where id=2;
这样呢?
zhaoyongzhu 2002-08-22
  • 打赏
  • 举报
回复
sorry,用where rownum=2不饱错。但却得不到我想要的结果。
zhaoyongzhu 2002-08-22
  • 打赏
  • 举报
回复
where rownum=2;肯定报错呀!!!!
bzszp 2002-08-22
  • 打赏
  • 举报
回复
select * from (select * from test1 order by pl desc) where rownum=2;
这个意思么?
javafish 2002-08-22
  • 打赏
  • 举报
回复
select id from (
select id from
(select id id from test1 union select pl id from test1 ) order by id desc)
where rownum <= 2;
bzszp 2002-08-22
  • 打赏
  • 举报
回复
SQL> select * from a5;

BBB CCC
--------- ---------
1 2
1 3
4 3
2 4
4 5

SQL> 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
javafish 2002-08-22
  • 打赏
  • 举报
回复
楼主自己好像都不知道要干什么?大家都在猜测着了,‘union all’?什么类型?怎么连接,哪个在前?都不知道!大家回答了这么多,你怎得把问题说清楚三
zhaoyongzhu 2002-08-22
  • 打赏
  • 举报
回复
非常感谢给位的参与。
问题虽然还没有解决,但找到了问题的根源了。

给分。
hdkkk 2002-08-22
  • 打赏
  • 举报
回复
select ID,ZYZ1,P1,DOCTIME,rank() over(order by id,p1) as rk from test1 where rk=2;
bzszp 2002-08-22
  • 打赏
  • 举报
回复
select aaa from (
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;
bzszp 2002-08-22
  • 打赏
  • 举报
回复
select aaa from (
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;
这样一般没问题
zhaoyongzhu 2002-08-22
  • 打赏
  • 举报
回复
to:bzszp(SongZip)
max(id)在id和p1所有的值中有可能只是第8大或。。。。。,所以你的SQL肯定不行。
不过非常感谢。
yuxuan 2002-08-22
  • 打赏
  • 举报
回复
同意楼上的
bzszp 2002-08-22
  • 打赏
  • 举报
回复
SQL> select * from a5;

BBB CCC
--------- ---------
1 2
1 3
4 3
2 4
4 5

SQL> select decode(sign(max(bbb)-max(ccc)),1,max(ccc),max(bbb)) second from a5;

SECOND
---------
4
bzszp 2002-08-22
  • 打赏
  • 举报
回复
select decode(sign(max(id)-max(pl)),1,max(pl),max(id)) from test1;
这样试试。
加载更多回复(2)
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧