|
Oracel Database 12c
1. Which assertion about the following queries is true? SELECT COUNT(DISTINCT mgr), MAX(DISTINCT salary) FROM
emp;
A. They will always return the same numbers in columns
1 and 2.
2. Which clauses in the SELECT statement can use single-row
functions nested in aggregate functions?
3. Consider the following two SQL statements.
1. select substr(first_name, 1,1) fn, SUM(salary) FROM
employees GROUP BY first_name;
A. Statement 1 and 2 will produce the same result.
4. How will the results of the following two SQL statements differ? Statement 1:
Statement 2:
A. Statement 1 will return one row, and statement 2 may
return more than one row.
5. Why does the following SELECT statement fail? SELECT colorname Colour, MAX(cost) FROM itemdetail
A. A GROUP BY clause cannot contain a column alias.
6. What will the following SQL statement return? select max(prod_pack_size)
A. An exception will be raised.
7. Why will the following query raise an exception? select dept_no, avg(distinct salary),
A. The HAVING clause cannot contain a group function.
8. Which clause will generate an error when the following query is executed? SELECT department_id, AVG(salary) avg_sal
A. The GROUP BY clause, because it is missing the group
function.
9. Which statements are true?
A. A group function can be used only if the GROUP BY clause
is present.
10. Read the following two statements, and choose the best option. 1. A HAVING clause should always appear after the GROUP
BY clause.
A. Statement 1 and 2 are false.
--- Answers: 1. B. The first column in the first query counts the distinct MGR values in the table. The first column in the second query counts all MGR values in the table. If a manager appears twice, the first query will count her one time, but the second will count her twice. Both the first query and the second query select the maximum salary value in the table. 2. A, B. A group function is not allowed in GROUP BY or WHERE clauses, whether you use it as nested or not. 3. B. Both statements are valid. The first statement will produce the number of rows equal to the number of unique first_name values. The second statement will produce the number of rows equal to the unique number of first characters in the first_name column. 4. D. COUNT(*) will count all rows in the table. COUNT(salary) will count only the number of salary values that appear in the table. If there are any rows with a NULL salary, statement 2 will not count them. 5. A. A GROUP BY clause must contain the column or expressions on which to perform the grouping operation. It cannot use column aliasing. 6. A. You cannot place a group function in the WHERE clause. Instead, you should use a HAVING clause. 7. B. There is at least one column in the SELECT list that is not a constant or group function, so a GROUP BY clause is mandatory. 8. D. The HAVING clause filters data after the group function is applied. If an aggregate function is not used in the HAVING clause, the column used must be part of the SELECT clause. 9. C. The HAVING clause can be used in a SELECT statement only if the GROUP BY clause is present. The optional HAVING clause filters data after the rows are summarized. 10. C. The GROUP BY and HAVING clauses can appear in any order in the SELECT clause. If a WHERE clause is present, it must be before the GROUP BY clause. ORDER BY clause, if present, follows the GROUP BY clause – ORDER BY is recommended for consistent result order. |
|
See Also
Do you have an Oracle Question? Oracle Books
Oracle Application
Oracle Home
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|