View the Exhibit and examine the structure of the CUSTOMERS table.
Which two tasks would require subqueries or joins to be executed in a single statement? (Choose two.)
A.
listing of customers who do not have a credit limit and were born before 1980
B.
finding the number of customers, in each city, whose marital status is ‘married’
C.
finding the average credit limit of male customers residing in ‘Tokyo’ or ‘Sydney’
D.
listing of those customers whose credit limit is the same as the credit limit of customers residing in the city
‘Tokyo’
E.
finding the number of customers, in each city, whose credit limit is more than the average credit limit of all
the customers
Explanation:
Describe the Types of Problems That the Subqueries Can Solve
There are many situations where you will need the result of one query as the input for another.
Use of a Subquery Result Set for Comparison Purposes
Which employees have a salary that is less than the average salary? This could be answered by two
statements, or by a single statement with a subquery. The following example uses two statements:
select avg(salary) from employees;
select last_name from employees where salary < result_of_previous_query ;
Alternatively, this example uses one statement with a subquery:
select last_name from employees where salary < (select avg(salary)from employees);
In this example, the subquery is used to substitute a value into the WHERE clause of the parent query: it is
returning a single value, used for comparison with the rows retrieved by the parent query.
The subquery could return a set of rows. For example, you could use the following to find all departments that
do actually have one or more employees assigned to them:
select department_name from departments where department_id in
(select distinct(department_id) from employees);
Use of a Subquery Result Set for Comparison Purposes.
Answer D&E
TestTaker
April 10, 2014 at 5:02 pm
With the first three statements you are trying to answer a question with two parts, but only one unknown.
1) Customers who do not have a credit limit (unknown) and were born before 1980 (known).
2) Number of customers in each city (unknown) and whose marital status is married (known).
3) Average credit limit of male customers (unknown) residing in Tokyo or Sydney (known).
The last two questions have two parts, but also two unknowns.
4) Number of customers who’s credit limit is (unknown) the same as the credit limit of customers residing in the city of Tokyo (also unknown).
5) Number of customers in each city (unknown) whose credit limit is more than the average of the credit limit of all the customers (also unknown).