edited by
21,152 views
85 votes
85 votes

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.$ Ties are not broke but ranks are skipped: if exactly two customers have the largest balance they each get rank $1$ and rank $2$ is not assigned.

$\text{Query1:}$ 

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

$\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 Query$1$ and Query$2.$

  1.  Query$1$ will produce the same row set as Query$2$ for some but not all databases. 
  2.  Both Query$1$ and Query $2$ are a correct implementation of the specification 
  3.  Query$1$ is a correct implementation of the specification but Query$2$ is not 
  4.  Neither Query$1$ nor Query$2$ 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?

  1. $2$ and $5$
  2. $1$ and $3$
  3. $1$ and $4$
  4. $3$ and $5$
edited by

6 Answers

0 votes
0 votes
Let us assume table has two customers with highest balance. According to given specification, the both should get rank 1.

Q1 results assigning both rank 2, and none get rank 1

Q2 results assign no rank(NULL) for both guys

Query 1 & 2 gives the same output for all not all data based its true because the balances may be distinct variables. Statement 1 is true.

Statement 5 is false as a single scan should be faster than a join query.

Thus we end up with option C
0 votes
0 votes

In statement  5 Relational query is used for performance Analysis.... based on balance assigns Rank and for scanning also takes same time so 5th statement also false 

 

hence option C is true 

Answer:

Related questions