diff --git a/SQL/PLSQL.sql b/SQL/PLSQL.sql index 7253299..174d778 100644 --- a/SQL/PLSQL.sql +++ b/SQL/PLSQL.sql @@ -1,12 +1,15 @@ + CREATE OR REPLACE FUNCTION mostValuableClerk(months IN NUMBER) RETURN NUMBER IS startMonat DATE; + finalclerkid NUMBER; + maxanzahlcleanings NUMBER; BEGIN startMonat := ADD_MONTHS(SYSDATE,-months); - SELECT MAX(Anzahl) FROM + SELECT CLERKID, MAX(Anzahl) INTO finalclerkid, maxanzahlcleanings FROM ( SELECT DISTINCT CLERKID, COUNT(CLERKID) AS Anzahl From @@ -17,7 +20,8 @@ BEGIN WHERE clpl."date" >= startMonat ) GROUP BY CLERKID - ); + ) + GROUP BY CLERKID; - return null; + return finalclerkid; END; \ No newline at end of file diff --git a/SQL/TestDaten.sql b/SQL/TestDaten.sql index 4664b98..e7309ea 100644 --- a/SQL/TestDaten.sql +++ b/SQL/TestDaten.sql @@ -9,4 +9,12 @@ INSERT INTO CLEANINGCLERK VALUES (1274689,124890); INSERT INTO BOOKING VALUES (124980,TO_DATE('2023-05-01', 'YYYY-MM-DD'),TO_DATE('2023-05-02', 'YYYY-MM-DD'),700,'No Pension',0,1274689); INSERT INTO BOOKINGROOM VALUES (124980,19724091); INSERT INTO BOOKINGGUEST VALUES (124980,1274689); -commit; \ No newline at end of file +commit; + + +DECLARE + clerkid NUMBER; +BEGIN + clerkid := mostValuableClerk(2); + DBMS_OUTPUT.PUT_LINE(clerkid); +end; \ No newline at end of file