I have 4 tables
EMPLOYEE
( E#, NAME
), primary key is E#
DRIVER
( E#, L#
), primary key is E#
references EMPLOYEE
TRIP
( T#, L#
), primary key is T#
, foreign key L#
references DRIVER
TRIPPT
( T#, PT#
) primary key is T#
references TRIP
I have create a function that finds the length (total number of pt#) of the longest point perform by the driver
My query so far:
create or replace function LONGPT (DL# in TRIP.L#%type)
return TRIPPT.PT#%type
IS
TRIPPT# TRIPPT.PT#%type;
begin
select max (PT#)
into TRIPPT#
from TRIPPT
where T# in (select T#
from TRIP
where L# = DL#);
return nvl (TRIPPT#, 0);
end LONGPT;
How can I do a select query to display the NAME
of the employee, LONGPT. The driver name that perform no trip point need to be in the query as well.
I have tried:
SELECT DRIVER.L# AS License_No, LONGTPT(TRIP.L#) AS "LONGEST POINT"
FROM DRIVER
LEFT OUTER JOIN TRIP on DRIVER.L# = TRIP.L#;
This only query the L# and the LONGEST Point.
Could anyone guide me how to do the select statement on display the NAME of the employee and with my function LONGPT.
Here is the working query i manage to figure out.
SELECT DISTINCT EMPLOYEE.NAME, LONGPT(TRIP.L#) AS "LONGEST Point"
FROM DRIVER Join EMPLOYEE ON DRIVER.E# = EMPLOYEE.E# LEFT OUTER JOIN
TRIP on DRIVER.L# = TRIP.L#;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.