📜  门| GATE-CS-2016(Set 2)|第62章

📅  最后修改于: 2021-06-29 18:27:05             🧑  作者: Mango

考虑以下名为water_schemes的数据库表:

11

以下SQL查询返回的元组数为

with total(name, capacity) as
   select district_name, sum(capacity)
   from water_schemes
   group by district_name
with total_avg(capacity) as
   select avg(capacity)
   from total
select name
   from total, total_avg
   where total.capacity >= total_avg.capacity

(A) 1
(B) 2
(C) 3
(D) 4答案: (B)
说明:按地区名称进行第一个分组,并按以下方式获得总容量

Ajmer 20
   Bikaner 40
   Charu 30
   Dungargarh 10 

然后计算平均容量,

Average Capacity = (20 + 40 + 30 + 10)/4 
                 = 100/4 
                 = 25.

最终,选择了超过平均水平的地区。

Bikaner is 40 which is greater than average (25)
Charu is 30 which is also greater than average (25). 

Therefore answer is 2 tuples.

这个问题的测验