📜  门| GATE-CS-2006 |第67章

📅  最后修改于: 2021-06-28 17:18:09             🧑  作者: Mango

考虑关系帐户(客户,余额),其中客户是主键,没有空值。我们希望根据余额减少对客户进行排名。余额最大的客户获得排名1。关系没有中断,但排名被跳过:如果恰好有两个客户具有最大的余额,则他们每个都获得排名1,而排名2不被分配

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

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

考虑有关Query1和Query2的这些语句。

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

以上哪两个陈述是正确的?
(A) 2和5
(B) 1和3
(C) 1和4
(D) 3和5答案: (C)
说明:如果所有客户都具有不同的余额,则查询1和查询2将给出相同的结果。因此,对于某些数据库,查询1和查询2的结果将相同。
现在,让我们考虑一个事实,即数据库中的所有条目都具有相同的余额值。理想情况下,所有客户的排名都应该为1,但是两个查询都将给所有客户一个等于数据库中客户数量的排名。
因此,两个查询都没有提供所需的输出。
因此,C是正确的选择。

如果您在以上文章中发现任何错误,请在下面发表评论。
这个问题的测验