SELECT c.customer_id, c.first_name, c.last_name FROM customer c INNER JOIN rental r ON c.customer_id = r.customer_id WHERE r.rental_date < (CURRENT_DATE - INTERVAL '12 months') AND ( r.return_date IS NULL OR r.return_date > (CURRENT_DATE - INTERVAL '12 months') ) AND c.customer_id NOT IN ( SELECT customer_id FROM rental WHERE rental_date >= (CURRENT_DATE - INTERVAL '12 months') ) GROUP BY c.customer_id;
SELECT
c.customer_id,
c.first_name,
c.last_name
FROM
customer c
INNER JOIN
rental r
ON c.customer_id = r.customer_id
WHERE
r.rental_date < (CURRENT_DATE - INTERVAL '12 months')
AND (
r.return_date IS NULL
OR r.return_date > (CURRENT_DATE - INTERVAL '12 months')
)
AND c.customer_id NOT IN (
SELECT
customer_id
FROM
rental
WHERE
rental_date >= (CURRENT_DATE - INTERVAL '12 months')
)
GROUP BY
c.customer_id;
This SQL statement is now formatted for PostgreSQL using proper indentation and line breaks for better readability.
- Public
- ·
- Tue, 11 Apr 2023 09:32:05 GMT