Advertisement
nnadnad

Untitled

Oct 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.48 KB | None | 0 0
  1. WITH tempTable(first_name,last_name,total) AS
  2.     (SELECT first_name, last_name,
  3.      (COUNT(DISTINCT rental.rental_id) + COUNT(DISTINCT payment_id)) AS total
  4.     FROM customer JOIN rental USING (customer_id) JOIN payment USING (customer_id)
  5.     GROUP BY first_name, last_name
  6.     ORDER BY first_name asc)
  7.     SELECT first_name, last_name, total,
  8.     CASE
  9.      WHEN total < 40 THEN 10
  10.      WHEN total >= 40 AND total < 60 THEN 20
  11.      ELSE 30
  12.     END AS discount
  13.     FROM tempTable;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement