Table: Account
| AccNo | Balance |
|---|---|
| A1 | 5000 |
| A2 | 5000 |
| A3 | 10000 |
| A4 | 15000 |
| A5 | 18000 |
SELECT AccNo FROM Account AS A
WHERE (SELECT COUNT(*) FROM Account AS B
WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
FROM Account AS C WHERE A.Balance > C.Balance)
A quicker way to see this is to first sort the balances and think in terms of rank. Sorted in increasing order, the balances are 5000, 5000, 10000, 15000, 18000, held by A1/A2, A1/A2, A3, A4, A5 respectively (A1 and A2 tie at 5000).
For any account A, countGreater is simply how many of the 5 balances are strictly above A's balance, and countLess is how many are strictly below it. The condition countGreater $\geq$ countLess is really asking whether an account sits at or below the "middle" of the distribution: values on the high end will always have more accounts below them than above, so they fail the test, while values on the low or middle end pass.
So the accounts that pass the filter are exactly those at or below the median balance: A1, A2, and A3. That gives 3 rows in the result.
$$\boxed{3}$$