Skip to content
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.
Puducherry TnboardTextbookSubjective· 3mImportance★★★★★
30% · 12/40 Questions
🔒 Locked · start free trial →

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:

InvoiceNoCarIdCustIdSaleDatePaymentModeEmpIDSalePrice
I00001D001C00012019-01-24Credit CardE004613247.00
I00002S001C00022018-12-12OnlineE001590321.00
I00003S002C00042019-01-25ChequeE010604000.00
I00004D002C00012018-10-15Bank FinanceE007659982.00
I00005E001C00032018-12-20Credit CardE002369310.00
I00006S002C00022019-01-30Bank FinanceE007620214.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:

EmpIDCOUNT(*)
E0011
E0021
E0041
E0072
E0101

(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.