sgd-praktikum/SQL/PLSQL.sql

38 lines
956 B
MySQL
Raw Normal View History

2023-05-12 16:52:59 +02:00
2023-05-12 17:09:20 +02:00
2023-05-12 16:52:59 +02:00
CREATE OR REPLACE FUNCTION mostValuableClerk(months IN NUMBER) RETURN NUMBER
IS
startMonat DATE;
2023-05-12 17:09:20 +02:00
finalclerkid NUMBER;
maxanzahlcleanings NUMBER;
2023-05-12 16:52:59 +02:00
BEGIN
startMonat := ADD_MONTHS(SYSDATE,-months);
2023-05-12 17:09:20 +02:00
SELECT CLERKID, MAX(Anzahl) INTO finalclerkid, maxanzahlcleanings FROM
2023-05-12 16:52:59 +02:00
(
SELECT DISTINCT CLERKID, COUNT(CLERKID) AS Anzahl
From
(
SELECT clcl.CLERKID
FROM CLEANINGCLERK clcl
INNER JOIN CLEANINGPLAN clpl ON clcl.CLEANINGPLANID = clpl.CLEANINGPLANID
WHERE clpl."date" >= startMonat
)
GROUP BY CLERKID
2023-05-12 17:09:20 +02:00
)
GROUP BY CLERKID;
2023-05-12 16:52:59 +02:00
2023-05-12 17:09:20 +02:00
return finalclerkid;
2023-05-12 17:20:58 +02:00
END;
CREATE OR REPLACE PROCEDURE getLastBookings(months IN NUMBER)
IS
CURSOR bookingsCursor IS SELECT BOOKINGID FROM BOOKING WHERE ARRIVALDATE >= ADD_MONTHS(SYSDATE,-months);
BEGIN
FOR booking IN bookingsCursor
LOOP
DBMS_OUTPUT.PUT_LINE(booking.BOOKINGID);
END LOOP;
2023-05-12 16:52:59 +02:00
END;