Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an SQL query that will display a list of all customers (lastName, firstNam

ID: 3918499 • Letter: W

Question

Write an SQL query that will display a list of all customers (lastName, firstName, phone) and the number of cars that each has purchased from the dealership. Sort the list by number of cars from most to least. Copy and paste your query in the large text area below. How many cars have been purchased by the customer who is listed third in the results of the query?

customer customerKey lastName firstName phone street1 street2 salesperson salesPersonkey lastName firstName hireDate salary purchase purchasekey dateSold odometer price customerKey salesPersonKey VIN state zipcode autom obile VIN year make model body color

Explanation / Answer

The SQL query is given below:

SELECT c.lastName, c.firstName, c.phone, p.NUMBER_OF_CARS FROM customer c JOIN ( SELECT count(*) AS NUMBER_OF_CARS FROM purchase GROUP BY customerKey) p ON c.customerKey = p.customerKey ORDER BY p.NUMBER_OF_CARS desc;

NOTE: To get the number of cars purchased by the customer who is listed third in the results of the query, just fetch the NUMBER_OF_CARS value from the third row.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote