Skip to content

Commit 8173e26

Browse files
committed
task 11
1 parent f873204 commit 8173e26

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

task11.sql

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
USE financial16_25;
2+
3+
DELIMITER $$
4+
DROP PROCEDURE IF EXISTS generate_cards_at_expiration_report;
5+
CREATE PROCEDURE generate_cards_at_expiration_report(p_date DATE)
6+
BEGIN
7+
TRUNCATE TABLE cards_at_expiration;
8+
INSERT INTO cards_at_expiration
9+
WITH cte AS (
10+
SELECT c2.client_id,
11+
c.card_id,
12+
date_add(c.issued, interval 3 year) as expiration_date,
13+
d2.A3
14+
FROM
15+
card as c
16+
INNER JOIN
17+
disp as d using (disp_id)
18+
INNER JOIN
19+
client as c2 using (client_id)
20+
INNER JOIN
21+
district as d2 using (district_id)
22+
)
23+
SELECT
24+
*,
25+
p_date
26+
FROM cte
27+
WHERE p_date BETWEEN DATE_ADD(expiration_date, INTERVAL -7 DAY) AND expiration_date
28+
;
29+
END;
30+
DELIMITER ;
31+
32+
CALL generate_cards_at_expiration_report('2001-01-01');
33+
SELECT * FROM cards_at_expiration;

0 commit comments

Comments
 (0)