Skip to content
Official PYQ · 2006

GATE CS 2006 Q67 — Tuple Calculus and SQL

Explain with AI

Consider the relation account (customer, balance) where the customer is a primary key and there are no null values. We would like to rank customers according to decreasing balance. The customer with the largest balance gets rank 1.1. Ties are not broke but ranks are skipped: if exactly two customers have the largest balance they each get rank 11 and rank 22 is not assigned.

Query1:\text{Query1:} 

select A.customer, count(B.customer)
from account A, account B
where A.balance <=B.balance
group by A.customer
 

Query2:\text{Query2:}

select A.customer, 1+count(B.customer)
from account A, account B
where A.balance < B.balance
group by A.customer

Consider these statements about Query11 and Query2.2.

  1.  Query11 will produce the same row set as Query22 for some but not all databases. 
  2.  Both Query11 and Query 22 are a correct implementation of the specification 
  3.  Query11 is a correct implementation of the specification but Query22 is not 
  4.  Neither Query11 nor Query22 is a correct implementation of the specification 
  5.  Assigning rank with a pure relational query takes less time than scanning in decreasing balance order assigning ranks using ODBC. 

Which two of the above statements are correct?

Choose one option
View worked solution

Answer: C

To determine which statements are correct, let us analyze both queries with a sample database of three customers:

  • C1C_1 with balance 100100
  • C2C_2 with balance 100100
  • C3C_3 with balance 5050

According to the specification, the correct ranks should be: C1→1C_1 \to 1, C2→1C_2 \to 1, and C3→3C_3 \to 3 (rank 2 is skipped).

1. Analysis of Query 1

Query 1 uses the join condition A.balance <= B.balance:

  • For C1C_1 (100100): B.balance≥100  ⟹  {C1,C2}B.balance \ge 100 \implies \{C_1, C_2\}. Count is 22.
  • For C2C_2 (100100): B.balance≥100  ⟹  {C1,C2}B.balance \ge 100 \implies \{C_1, C_2\}. Count is 22.
  • For C3C_3 (5050): B.balance≥50  ⟹  {C1,C2,C3}B.balance \ge 50 \implies \{C_1, C_2, C_3\}. Count is 33.

The output ranks are C1→2C_1 \to 2, C2→2C_2 \to 2, C3→3C_3 \to 3. This is incorrect because the top rank is 22 instead of 11. Thus, Query 1 is incorrect.

2. Analysis of Query 2

Query 2 uses the join condition A.balance < B.balance:

Because of the inner join, any customer AA who has the absolute maximum balance will find no customer BB with a strictly greater balance (i.e., A.balance < B.balance is false for all BB). Consequently, the maximum balance customer(s) are completely filtered out and omitted from the final output. Thus, Query 2 is also incorrect.

Since neither query is correct, Statement 4 is correct.

3. Analysis of Statement 1

  • If the database is empty, both Query 1 and Query 2 produce an empty result set (they are identical).
  • For any non-empty database, Query 1 will output the maximum balance customer(s), whereas Query 2 will omit them. Thus, their outputs will differ.

Hence, Query 1 produces the same row set as Query 2 for some (empty) but not all databases. This makes Statement 1 correct.

Therefore, statements 1 and 4 are correct, matching Option C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions