-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFUNCTION_average_ticket_prices.sql
More file actions
40 lines (31 loc) · 1002 Bytes
/
FUNCTION_average_ticket_prices.sql
File metadata and controls
40 lines (31 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--********************************************************************
--**
--** Function: f_average_ticket_price
--** In:
--** Returns: average price of a ticket last month
--** Developer: Jakob List
--** Description: calculates the average price of a ticket last month
--*
--********************************************************************
CREATE OR REPLACE FUNCTION f_average_ticket_price RETURN NUMBER IS
n_avg_preis NUMBER;
BEGIN
SELECT AVG(preis)
INTO n_avg_preis
FROM ticket t
LEFT JOIN one_time_ticket ot ON t.ticketid = ot.fk_ticketid
LEFT JOIN mehrfachticket mt ON t.ticketid = mt.fk_ticketid
WHERE kaufdatum >= CURRENT_TIMESTAMP+INTERVAL '-1' MONTH
AND kaufdatum <= CURRENT_TIMESTAMP
ORDER BY t.ticketid ASC;
RETURN n_avg_preis;
EXCEPTION WHEN no_data_found THEN dbms_output.put_line ('Kein Ticket wurde verkauft.');
RETURN -1;
WHEN OTHERS THEN dbms_output.put_line ('Fehler aufgetreten.');
RETURN -1;
END;
/
BEGIN
dbms_output.put_line(f_average_ticket_price);
END;
/