Open psql or pgAdmin and create a new database: CREATE DATABASE dvdrental; Use code with caution.
Providing to solve complex analytical problems using this database. dvdrental
// Calculate late fee const fee = await pool.query( SELECT calculate_late_fee($1) AS fee , [rentalId]); Open psql or pgAdmin and create a new
// Update return date await pool.query( UPDATE rental SET return_date = NOW() WHERE rental_id = $1 , [rentalId]); f.title AS film_title
CREATE OR REPLACE VIEW overdue_rentals AS SELECT r.rental_id, c.customer_id, c.first_name, c.last_name, c.email, f.title AS film_title, r.rental_date, r.return_date, CURRENT_DATE - r.rental_date::DATE AS days_rented, f.rental_duration, CASE WHEN r.return_date IS NULL AND (CURRENT_DATE - r.rental_date::DATE) > f.rental_duration THEN (CURRENT_DATE - r.rental_date::DATE) - f.rental_duration ELSE 0 END AS days_overdue FROM rental r JOIN customer c ON r.customer_id = c.customer_id JOIN inventory i ON r.inventory_id = i.inventory_id JOIN film f ON i.film_id = f.film_id WHERE r.return_date IS NULL AND (CURRENT_DATE - r.rental_date::DATE) > f.rental_duration;
-- Process payment for customer ID 5 CALL process_late_fee_payment(5, 15.00);