Activities · Activity 1.6
Q.(a) List the total number of cars sold by each employee.
(b) List the maximum sale made by each employee.
Yanam BieapTextbookSubjective· 3mImportance★★★★★
30% · 12/40 Questions
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 →Both parts GROUP BY EmpID on the real SALE table — (a) counts rows per group with COUNT(*),
(b) finds the largest SalePrice per group with MAX(SalePrice).
This is a code/query task on the SALE table of CARSHOWROOM:
| InvoiceNo | CarId | CustId | SaleDate | PaymentMode | EmpID | SalePrice |
|---|---|---|---|---|---|---|
| I00001 | D001 | C0001 | 2019-01-24 | Credit Card | E004 | 613247.00 |
| I00002 | S001 | C0002 | 2018-12-12 | Online | E001 | 590321.00 |
| I00003 | S002 | C0004 | 2019-01-25 | Cheque | E010 | 604000.00 |
| I00004 | D002 | C0001 | 2018-10-15 | Bank Finance | E007 | 659982.00 |
| I00005 | E001 | C0003 | 2018-12-20 | Credit Card | E002 | 369310.00 |
| I00006 | S002 | C0002 | 2019-01-30 | Bank Finance | E007 | 620214.00 |
(a) GROUP BY EmpID collects all rows for the same salesperson into one group; COUNT(*) then counts how many sale rows fall into each group:
SELECT EmpID, COUNT(*) FROM SALE GROUP BY EmpID;
E007 appears in two rows (I00004, I00006), so their count is 2. Every other EmpID (E001, E002, E004, E010) appears exactly once:
| EmpID | COUNT(*) |
|---|---|
| E001 | 1 |
| E002 | 1 |
| E004 | 1 |
| E007 | 2 |
| E010 | 1 |
(b) Same grouping, but MAX(SalePrice) instead of COUNT(*) — it picks the single highest SalePrice within each employee's group:
SELECT EmpID, MAX(SalePrice) FROM SALE GROUP BY EmpID;
``` …
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.