GATE DA 2026 · SQL Queries

NAT · 2 marks · Problem DBMS-SQL-0042

Let Account be a relation as shown.\(\textbf{Account}\)\[\begin{array}{|c|c|} \hline \text{AccNo} & \text{Balance} \\ \hline \text{A1} & 5000 \\ \hline \text{A2} & 5000 \\ \hline \text{A3} & 10000 \\ \hline \text{A4} & 15000 \\ \hline \text{A5} & 18000 \\ \hline \end{array}\]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)

Numerical answer (NAT).

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{row kept} \iff \#\{\text{higher balances}\} \ge \#\{\text{lower balances}\}}\]\[\begin{array}{c|c|c|c|c}\text{Acc}&\text{Balance}&\text{\#Higher}&\text{\#Lower}&\text{Higher}\ge\text{Lower?}\\ \hline A1&5000&3&0&\text{Yes}\\A2&5000&3&0&\text{Yes}\\A3&10000&2&2&\text{Yes}\\A4&15000&1&3&\text{No}\\A5&18000&0&4&\text{No}\end{array}\]Accounts A1, A2 and A3 satisfy the condition: \(3\) rows.Answer: 3

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com