Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH tempTable(first_name,last_name,total) AS
- (SELECT first_name, last_name,
- (COUNT(DISTINCT rental.rental_id) + COUNT(DISTINCT payment_id)) AS total
- FROM customer JOIN rental USING (customer_id) JOIN payment USING (customer_id)
- GROUP BY first_name, last_name
- ORDER BY first_name asc)
- SELECT first_name, last_name, total,
- CASE
- WHEN total < 40 THEN 10
- WHEN total >= 40 AND total < 60 THEN 20
- ELSE 30
- END AS discount
- FROM tempTable;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement