GATE 2026 DA – Question 60
Let Account be a relation as shown.
| AccNo | Balance |
|---|---|
| A1 | 5000 |
| A2 | 5000 |
| A3 | 10000 |
| A4 | 15000 |
| A5 | 18000 |
Consider the given SQL query.
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)The number of rows returned by the SQL query is __________ . (*Answer in integer*)
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 3
Explanation
For each account the query compares the number of accounts with a larger balance to the number with a smaller balance and keeps the account when the first number is at least the second. A1 and A2 (5000): 3 larger, 0 smaller, kept. A3 (10000): 2 larger (15000, 18000) and 2 smaller (5000, 5000), kept because $2 \ge 2$. A4 (15000): 1 larger and 3 smaller, rejected. A5 (18000): 0 larger and 4 smaller, rejected. So 3 rows are returned.