SQL & Queries


Answer & solution
Answer: C (no official key was published)
1. Query1 counts B rows with A.balance≤B.balance, so a customer tied with t customers at its balance receives the count of higher-balance customers plus t, instead of plus 1. For two tied maximum balances it gives 2, not 1.
2. Query2 uses A.balance<B.balance and adds 1 to the count, but its inner join produces no group for maximum-balance customers; those customers disappear. Thus neither query is correct (statement 4).
3. They agree on the empty database but differ on every nonempty database because Query1 includes the maximum group and Query2 does not, establishing statement 1 under the allowed empty-database case. Hence statements 1 and 4, option C.
4. Statement 5 is not a general performance guarantee.
5. Teaching check: The intended rank is 1 plus the number of strictly higher balances. Q1 instead counts all tied customers along with higher ones. Q2 uses the correct comparison but an inner join removes maxima, so adding one to its count does not restore the missing rows.