I have 3 tables.
driver, trip, tripLegs
In driver table the columns are E#, L#, STATUS.
In trip table the columns are T#, L#, REG#, trip_DATE
In tripLeg table the columns are T#, LEG#, DEPARTURE, DESTINATION
First I tried a sql query which is:
select d.l#, count(tg.leg#) as total_no_of_legs
from driver d left outer join trip t on (d.l# = t.l#)
left outer join tripleg tg on (t.t# = tg.t#)
group by d.l#;
Results i got was:
L# Total_no_of_legs
-----------------------------
11111 20
and so on.
This is the total number of legs from all T#’s leg#
e.g
T#1 's leg# = 3
T#2's leg# = 10
T#3's leg# = 7
Total = 20 that is why L# 11111 total no of Legs is 20.
But I wanna find out the max leg# of each L# which is 10.
How do I do a query to find out highest number of LEG# group by T#?
Afterwhich, how do I really start to convert this into a PL/SQL statement?
Have been wondering all day and reading up on books. Still couldnt find a solution to it
Maybe I’m missing something, but isn’t that simply:
I don’t see the need to put this into a stored procedure.
To put this into a function that returns the result, you need a pipelined function:
You can then use this function like this: