edited by
642 views
1 1 vote

Let Account be a relation as shown.

\[
\textbf{Account}
\]

\[
\renewcommand{\arraystretch}{1.3}
\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)

1 Answer

2 2 votes
Given relation Account:

\[
\begin{array}{cc}
\text{AccNo} & \text{Balance} \\
\hline
A1 & 5000 \\
A2 & 5000 \\
A3 & 10000 \\
A4 & 15000 \\
A5 & 18000
\end{array}
\]

The SQL query checks, for each tuple A, whether

\[
\#\{\text{Balances greater than } A.\text{Balance}\}
\;\ge\;
\#\{\text{Balances smaller than } A.\text{Balance}\}.
\]

Now evaluate for each row.

For A1 (5000):

Greater balances: 10000, 15000, 18000 → 3

Smaller balances: none → 0  

\[
3 \ge 0 \quad \text{True}
\]

For A2 (5000):

Greater balances: 3  

Smaller balances: 0  

\[
3 \ge 0 \quad \text{True}
\]

For A3 (10000):

Greater balances: 15000, 18000 → 2  

Smaller balances: 5000, 5000 → 2  

\[
2 \ge 2 \quad \text{True}
\]

For A4 (15000):

Greater balances: 18000 → 1  

Smaller balances: 5000, 5000, 10000 → 3  

\[
1 \ge 3 \quad \text{False}
\]

For A5 (18000):

Greater balances: none → 0  

Smaller balances: 5000, 5000, 10000, 15000 → 4  

\[
0 \ge 4 \quad \text{False}
\]

Thus, the rows satisfying the condition are:

\[
A1,\; A2,\; A3
\]

Total number of rows returned:

\[
\boxed{3}
\]
moved by
Answer:
Position:
Show:

Related questions

1 1 vote
2 2 answers
565
565 views
gatecse asked Feb 23
565 views
Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the em...
2 2 votes
2 2 answers
773
773 views
gatecse asked Feb 23
773 views
Let there be two relations $X$ and $Y$ as shown. $X$ has three columns $P, Q$ and $R . Y$ has two columns $P$ and $S$.\[\textbf{X}\]\[\begin{array}{|c|c|c|}\hlineP & Q & ...
0 0 votes
2 2 answers
772
772 views
gatecse asked Feb 23
772 views
Consider an $\text{ER}$ model with the entities $\text{E1}$ ( $\mathrm{A}_{11}, \mathrm{~A}_{12}, \mathrm{~A}_{13}$ ) and $\text{E2}$ ( $\mathrm{A}_{21}, \mathrm{~A}_{22}...
0 0 votes
0 0 answers
206
206 views
js__ asked Nov 24, 2025
206 views
Should we answer according to the latest version which is in real life practical or stick to the old versions in standard text books ? @Deepak Poonia @Sachin Mittal 1 Que...