Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> can this be done more elegant?

can this be done more elegant?

From: <willemreinders_at_gmail.com>
Date: 19 Apr 2006 08:08:20 -0700
Message-ID: <1145459300.371090.169030@z34g2000cwc.googlegroups.com>


I want to select from a test ride table the data of the last Right Curve. I can do that by the select as given below. My problem is that this select is quite inefficient, because the same basic select is performed twice (once to obtain the time tag and once to obtain the measurement data).
In cases of heavily joined, more complex selects the same select has to be repeated almost exactly. I have the feeling that this can be solved more elegant. Any idea's?

create table test_ride (
  time number,
  event_type varchar2(10),
  speed number
);
--

insert into test_ride values ( 1.20, 'curve_L', 90.2);
insert into test_ride values (11.45, 'curve_R', 89.6);
insert into test_ride values (21.80, 'brake'   , 102.2);
insert into test_ride values (21.98, 'curve_R', 79.3);
insert into test_ride values (41.99, 'curve_R', 60.1);
insert into test_ride values (41.03, 'curve_L', 69.7);
insert into test_ride values (51.32, 'curve_R', 122.3);
insert into test_ride values (51.20, 'curve_L', 128.9);
insert into test_ride values (51.65, 'brake'   , 93.1);

--

select *
from test_ride
where time = (
  select MAX(time)
  from test_ride
  where event_type = 'curve_R'
)
and event_type = 'curve_R'
; Received on Wed Apr 19 2006 - 10:08:20 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US