Skip to main contentSkip to solution

Given the following table:

SALE

CustIdPaymentModeEmpIdSalePriceCommission
c01Credit CardE00461200.005000.00
c02onlineE00147500.002000.00
c03ChequeE00552500.004000.00
c01Credit CardE00268000.007000.00
c04ChequeE00464500.003800.00
c02Bank FinanceE00361500.004200.00

Which query will display the number of people in each category of attribute PaymentMode from the table?

Solution

✅ Correct Option: 1

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.

PaymentModeCOUNT(PaymentMode)
Bank Finance1
Cheque2
Credit Card2
online1

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question