Q.a) List the total number of cars sold by each employee.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →This question asks for two SQL aggregation queries on the real SALE table of the CARSHOWROOM database (Table 9.11) — there is no separate CarSales table in this schema. The core idea is GROUP BY with aggregate functions COUNT() and MAX().
The real SALE table (Table 9.11)
| InvoiceNo | CarId | CustId | EmpID | SalePrice |
|---|---|---|---|---|
| I00001 | D001 | C0001 | E004 | 613248.00 |
| I00002 | S001 | C0002 | E001 | 590321.00 |
| I00003 | S002 | C0004 | E010 | 604000.00 |
| I00004 | D002 | C0001 | E007 | 659982.00 |
| I00005 | E001 | C0003 | E002 | 369310.00 |
| I00006 | S002 | C0002 | E007 | 620214.00 |
Each row of SALE already represents one car sold by one employee (EmpID), so GROUP BY EmpID on this real table directly answers both parts — no separate CarSales table is needed or exists in this schema.
a) List the total number of cars sold by each employee.
SELECT EmpID, COUNT(*) AS TotalCarsSold
FROM SALE
GROUP BY EmpID;
COUNT(*) counts the rows in each employee's group — each row is one car sold. Employee E007 appears twice (I00004 and I00006); every other employee in this data sold exactly one car.
Output
| EmpID | TotalCarsSold |
|---|---|
| E001 | 1 |
| E002 | 1 |
| E004 | 1 |
| E007 | 2 |
| E010 | 1 |
b) List the maximum sale made by each employee.
SELECT EmpID, MAX(SalePrice) AS MaxSale
FROM SALE …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.