1. Query the top 3 customer’s names who spent the most on rentalfilms. Display customer id, name and the amount spent.
This is my approached but seems like it is wrong. I may miss theWHERE clause and make a relationship between customer and paymenttables
SELECT customer.customer_id, customer.first_name,customer.last_name, SUM(amount) AS amount_spentFROM customer, paymentGrOUP BY customer_idORDER BY amount_spent LIMIT 3;
customer_id store_id 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 1 1 2 1 2 1 -2212-22 first_name last_name email MARY SMITH [email protected] 5 PATRICIA JOHNSON 6 LINDA 7 8 BARBARA JONES ELIZABETH BROWN 9 JENNIFER DAVIS 10 11 [email protected] WILLIAMS [email protected] [email protected] [email protected] [email protected] MILLER [email protected] WILSON [email protected] MARGARET MOORE [email protected] 13 DOROTHY TAYLOR [email protected] LISA ANDERS... [email protected] THOMAS [email protected] JACKSON [email protected] WHITE [email protected] 12 14 15 16 17 18 MARIA SUSAN address_id active create_date NANCY KAREN BETTY last_update 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04:5 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04: 2006-02-14 22:04:36 2006-02-15 04:5 2006-02-14 22:04:36 2006-02-15 04: 2006-02-15 04: 2006-02-14 22:04:36 2006-02-14 22:04:36 2006-02-15 04:5 1 1 1 1 1 1 1 1 1 1 1 1 1 1
payment_id customer_id staff_id rental_id amount payment_date 2.99 0.99 5.99 0.99 9.99 4.99 4.99 0.99 2005-05-25 11:30:37 2005-05-28 10:35:23 2005-06-15 00:54:12 2005-06-15 18:02:53 2005-06-15 21:08:46 2005-06-16 15:18:57 2005-06-18 08:41:48 2005-06-18 13:33:59 2005-06-21 06:24:45 2005-07-08 03:17:05 2005-07-08 07:33:56 2005-07-09 13:24:07 2005-07-09 16:38:01 2005-07-11 10:13:46 2005-07-27 11:31:22 3.99 5.99 5.99 4.99 4.99 7.99 2.99 1.99 2005-07-28 00:01:15 ▶1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 1 2 1 76 573 1185 1422 1476 1725 2308 2363 3284 4526 4611 5244 5326 6163 7273 7811 last_update 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22:12:30 2006-02-15 22-12-20
1. Query the top 3 customer’s names who spent the most on rental films. Display customer id, name and the amount spent.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am