简体   繁体   English

我如何运行SQL函数QUERY

[英]How do i run SQL function QUERY

I have 4 tables 我有4张桌子

  • EMPLOYEE ( E#, NAME ), primary key is E# EMPLOYEEE#, NAME ),主键是E#
  • DRIVER ( E#, L# ), primary key is E# references EMPLOYEE DRIVERE#, L# ),主键是E#引用EMPLOYEE
  • TRIP ( T#, L# ), primary key is T# , foreign key L# references DRIVER TRIPT#, L# ),主键为T# ,外键L#引用DRIVER
  • TRIPPT ( T#, PT# ) primary key is T# references TRIP TRIPPTT#, PT# )主键是T#引用的TRIP

I have create a function that finds the length (total number of pt#) of the longest point perform by the driver 我创建了一个函数,该函数查找驱动程序执行的最长点的长度(pt#的总数)

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. 如何执行选择查询以显示员工的NAME 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. 这仅查询L#和最长点。

Could anyone guide me how to do the select statement on display the NAME of the employee and with my function LONGPT. 谁能指导我如何在雇员姓名和我的函数LONGPT上显示select语句。

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#; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM