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 colorExplanation / 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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.