Given the following table:
SALE
CustId PaymentMode EmpId SalePrice Commission c01 Credit Card E004 61200.00 5000.00 c02 online E001 47500.00 2000.00 c03 Cheque E005 52500.00 4000.00 c01 Credit Card E002 68000.00 7000.00 c04 Cheque E004 64500.00 3800.00 c02 Bank Finance E003 61500.00 4200.00
Which query will display the number of people in each category of attribute PaymentMode from the table?
Given the following table:
SALE
| CustId | PaymentMode | EmpId | SalePrice | Commission |
|---|---|---|---|---|
| c01 | Credit Card | E004 | 61200.00 | 5000.00 |
| c02 | online | E001 | 47500.00 | 2000.00 |
| c03 | Cheque | E005 | 52500.00 | 4000.00 |
| c01 | Credit Card | E002 | 68000.00 | 7000.00 |
| c04 | Cheque | E004 | 64500.00 | 3800.00 |
| c02 | Bank Finance | E003 | 61500.00 | 4200.00 |
Which query will display the number of people in each category of attribute PaymentMode from the table?
Solution
GROUP BY PaymentMode makes one group for each payment mode, and COUNT(PaymentMode) counts the rows in each group. ORDER BY PaymentMode then sorts the output alphabetically.
| PaymentMode | COUNT(PaymentMode) |
|---|---|
| Bank Finance | 1 |
| Cheque | 2 |
| Credit Card | 2 |
| online | 1 |
Option 3: it groups by CustId, so it counts per customer, not per payment mode. PaymentMode is also not a grouped column.
Option 4: SELECT * with GROUP BY on a single column is invalid, because the other columns are neither grouped nor aggregated.
We believe the answer could be Option 2 as well, since it returns the same counts per PaymentMode, only without sorting. However, NTA's final answer key (after all challenges) says Option 1.
Related questions:
2026: 26 May Shift 1
2025: 15 May Shift 2
2026: 29 May Shift 2