Skip to main contentSkip to solution

Fill in the words from below to complete the query in the correct order to display the PaymentMode and the number of payments made using that mode more than once from the relation 'SALE'.

_______ PaymentMode, COUNT(PaymentMode) _____ SALE ________ PaymentMode _________ COUNT(*)>1 ORDER BY PaymentMode;

(A) HAVING

(B) FROM

(C) SELECT

(D) GROUP BY

Solution

✅ Correct Option: 1

The blanks fill in SQL's clause order: SELECT, FROM, GROUP BY, HAVING.

SELECT PaymentMode, COUNT(PaymentMode) FROM SALE GROUP BY PaymentMode HAVING COUNT(*)>1 ORDER BY PaymentMode;

GROUP BY puts the rows into one group per payment mode. HAVING then keeps only the groups with more than one payment, because it filters groups after aggregation.


Option 2: HAVING cannot come before GROUP BY, since it filters the groups that GROUP BY creates.

Remember that WHERE filters rows before grouping, while HAVING filters groups after grouping. An aggregate such as COUNT(*) can only be used in HAVING.

Keyboard Shortcuts

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