October 4, 2023
October 4, 2023
October 4, 2023
SQL
October 4, 2023
 Question 34

Consider the following database table named water_schemes :

The number of tuples returned by the following SQL query is _________.

```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 2 B 3 C 4 D 5
Question 34 Explanation:
• The SQL WITH clause allows you to give a sub-query block a name (a process also called sub-query refactoring), which can be referenced in several places within the main SQL query.
The name assigned to the sub-query is treated as though it was an inline view or table.

• First group by district name is performed and total capacities are obtained as following:

• Then average capacity is computed,
Average Capacity = (20 + 40 + 30 + 10)/4
= 100/4
= 25
• Finally, 3rd query will be executed and it’s tuples will be considered as output, where name of district and its total capacity should be more than or equal to 25.
• Then average capacity is computed,
Average Capacity = (20 + 40 + 30 + 10)/4
= 100/4
= 25
• Finally, 3rd query will be executed and it’s tuples will be considered as output, where name of district and its total capacity should be more than or equal to 25.

Question 34 Explanation:
• The SQL WITH clause allows you to give a sub-query block a name (a process also called sub-query refactoring), which can be referenced in several places within the main SQL query.
The name assigned to the sub-query is treated as though it was an inline view or table.

• First group by district name is performed and total capacities are obtained as following:

• Then average capacity is computed,
Average Capacity = (20 + 40 + 30 + 10)/4
= 100/4
= 25
• Finally, 3rd query will be executed and it’s tuples will be considered as output, where name of district and its total capacity should be more than or equal to 25.
• Then average capacity is computed,
Average Capacity = (20 + 40 + 30 + 10)/4
= 100/4
= 25
• Finally, 3rd query will be executed and it’s tuples will be considered as output, where name of district and its total capacity should be more than or equal to 25.