Mid Exam Part2, Var 3

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 21

Section 5 1. CUBE can be applied to all aggregate functions including AVG, SUM, MIN, MAX, and COUNT.

True or False? Mark for Review (1) Points True (*) False Correct 2. You use ROLLUP to: Mark for Review (1) Points produce subtotal values (*) cross-tabulate values produce a single result set Correct 3. You use GROUPING function to: Mark for Review (1) Points Produce subtotal and cross-tabulated values Identify the extra row values created by either a ROLLUP or CUBE operation (*) Aggregate rows using SUM, MIN, MAX, and COUNT Incorrect. Refer to Section 5 Lesson 2. 4. You use GROUPING function to ______ database rows from tabulated rows. Mark for Review (1) Points CREATE DISTINGUISH (*) COMPUTE COUNT Correct 5. To control the order of rows returned using SET operators, the ORDER BY clause is used ______ and is placed in the _____ SELECT statement of the query. Mark for Review (1) Points

ONCE; FIRST TWICE; FIRST ONCE; LAST (*) IN ALL; LAST Incorrect. Refer to Section 5 Lesson 3. 6. When using SET operators the names of the columns must be identified in all of the SELECT statements used in the query. True or False? Mark for Review (1) Points True False (*) Correct 7. The EMPLOYEES table contains the following columns: EMPLOYEE_ID NUMBER(10) PRIMARY KEY LAST_NAME VARCHAR2(20) FIRST_NAME VARCHAR2(20) DEPARTMENT VARCHAR2(20) HIRE_DATE DATE SALARY NUMBER(10) You want to create a report that includes each employee's last name, employee identification number, date of hire and salary. The report should include only those employees who have been with the company for more than one year and whose salary exceeds $40,000. Which of the following SELECT statements will accomplish this task? Mark for Review (1) Points SELECT employee_id, last_name, salary FROM employees WHERE salary > 40000 AND hire_date = (SELECT hire_date FROM employees WHERE (sysdate-hire_date) / 365 > 1); SELECT employee_id, last_name, hire_date, salary FROM employees WHERE salary > 40000 AND hire_date = (SELECT hire_date FROM employees WHERE (sysdate-hire_date) / 365 > 1); SELECT employee_id, last_name, hire_date, salary

FROM employees WHERE salary > 40000 AND (sysdate-hire_date) / 365 > 1; (*) SELECT employee_id, last_name, salary FROM employees WHERE salary > 40000 AND hire_date IN (sysdate-hire_date) / 365 > 1);

Incorrect. Refer to Section 5 Lesson 1. 8. Evaluate this statement: SELECT department_id, AVG(salary) FROM employees WHERE job_id <> 69879 GROUP BY job_id, department_id HAVING AVG(salary) > 35000 ORDER BY department_id; Which clauses restricts the result? Choose two. Mark for Review (1) Points (Choose all correct answers) SELECT department_id, AVG(salary) WHERE job_id <> 69879 (*) GROUP BY job_id, department_id HAVING AVG(salary) > 35000 (*) Incorrect. Refer to Section 5 Lesson 1. 9. Evaluate this SELECT statement: SELECT SUM(salary), department_id, department_name FROM employees WHERE department_id = 1 GROUP BY department; Which clause of the SELECT statement contains a syntax error? Mark for Review (1) Points SELECT FROM WHERE GROUP BY (*)

Incorrect. Refer to Section 5 Lesson 1. 10. The PAYMENT table contains these columns: PAYMENT_ID NUMBER(9) PK PAYMENT_DATE DATE CUSTOMER_ID NUMBER(9) Which SELECT statement could you use to display the number of times each customer payment was made between January 1, 2003 and June 30, 2003 ? Mark for Review (1) Points SELECT customer_id, COUNT(payment_id) FROM payment WHERE payment_date BETWEEN '01-JAN-2003' AND '30-JUN-2003' GROUP BY customer_id; (*) SELECT COUNT(payment_id) FROM payment WHERE payment_date BETWEEN '01-JAN-2003' AND '30-JUN-2003'; SELECT customer_id, COUNT(payment_id) FROM payment WHERE payment_date BETWEEN '01-JAN-2003' AND '30-JUN-2003'; SELECT COUNT(payment_id) FROM payment WHERE payment_date BETWEEN '01-JAN-2003' AND '30-JUN-2003' GROUP BY customer_id;

Incorrect. Refer to Section 5 Lesson 1. Section 5 11. If a select list contains both a column as well as a group function then what clause is required? Mark for Review (1) Points HAVING clause JOIN clause ORDER BY clause GROUP BY clause (*) Incorrect. Refer to Section 5 Lesson 1. 12. Which statement about group functions is true? (1) Points Mark for Review

Group functions ignore null values. (*) Group functions can only be used in a SELECT list. Group functions can be used in a WHERE clause. A query that includes a group function in the SELECT list must include a GROUP BY clause. Incorrect. Refer to Section 5 Lesson 1. 13. Which statement about the GROUP BY clause is true? (1) Points Mark for Review

To exclude rows before dividing them into groups using the GROUP BY clause, you should use a WHERE clause. (*) You can use a column alias in a GROUP BY clause. By default, rows are not sorted when a GROUP BY clause is used. You must use the HAVING clause with the GROUP BY clause. Incorrect. Refer to Section 5 Lesson 1. 14. The PLAYERS table contains these columns: PLAYER_ID NUMBER PK PLAYER_NAME VARCHAR2 (30) TEAM_ID NUMBER HIRE_DATE DATE SALARY NUMBER (8,2) Which clauses represent valid uses of aggregate functions? (Choose three.) Mark for Review (1) Points (Choose all correct answers) ORDER BY AVG(salary) (*) GROUP BY MAX(salary) SELECT AVG(NVL(salary, 0)) (*) HAVING MAX(salary) > 10000 (*) WHERE hire_date > AVG(hire_date) Incorrect. Refer to Section 5 Lesson 1. 15. What is the best explanation as to why this SQL statement will NOT execute? SELECT department_id "Department", AVG (salary)"Average" FROM employees GROUP BY Department;

Mark for Review (1) Points Salaries cannot be averaged as not all the numbers will divide evenly. You cannot use a column alias in the GROUP BY clause. (*) The GROUP BY clause must have something to GROUP. The department id is not listed in the departments table. Correct 16. What is the correct order of clauses in a SELECT statement? for Review (1) Points SELECT FROM WHERE ORDER BY GROUP BY HAVING SELECT FROM HAVING GROUP BY WHERE ORDER BY SELECT FROM WHERE GROUP BY HAVING ORDER BY (*) SELECT FROM WHERE HAVING ORDER BY GROUP BY Mark

Incorrect. Refer to Section 5 Lesson 1. 17. Evaluate this SELECT statement: SELECT COUNT(employee_id), department_id FROM employees GROUP BY department_id;

You only want to include employees who earn more than 15000. Which clause should you include in the SELECT statement? Mark for Review (1) Points WHERE salary > 15000 (*) HAVING salary > 15000 WHERE SUM(salary) > 15000 HAVING SUM(salary) > 15000 Incorrect. Refer to Section 5 Lesson 1. 18. The MANUFACTURER table contains these columns: MANUFACTURER_ID NUMBER MANUFACTURER_NAME VARCHAR2(30) TYPE VARCHAR2(25) LOCATION_ID NUMBER You need to display the number of unique types of manufacturers at each location. Which SELECT statement should you use? Mark for Review (1) Points SELECT location_id, COUNT(DISTINCT type) FROM manufacturer GROUP BY location_id; (*) SELECT location_id, COUNT(DISTINCT type) FROM manufacturer; SELECT location_id, COUNT(type) FROM manufacturer GROUP BY location_id; SELECT location_id, COUNT(DISTINCT type) FROM manufacturer GROUP BY type;

Incorrect. Refer to Section 5 Lesson 1. 19. Evaluate this SELECT statement: SELECT MAX(salary), department_id FROM employees GROUP BY department_id; Which values are displayed? Mark for Review (1) Points The highest salary for all employees.

The highest salary in each department. (*) The employees with the highest salaries. The employee with the highest salary for each department. Correct

Section 6 20. Which best describes a single-row subquery? (1) Points Mark for Review

A query that returns only one row from the inner SELECT statement (*) A query that returns one or more rows from the inner SELECT statement A query that returns only one column value from the inner SELECT statement A query that returns one or more column values from the inner SELECT statement Correct Section 6 21. If a single-row subquery returns a null value and uses the equality comparison operator, what will the outer query return? Mark for Review (1) Points No rows (*) All the rows in the table A null value An error Correct 22. Which statement is false? Mark for Review (1) Points The WITH clause retrieves the results of one or more query blocks. The WITH clause decreases performance. (*) The WITH clause makes the query simple to read . Stores the results for the user who runs the query.

Incorrect. Refer to Section 6 Lesson 4. 23. A correlated subquery will _______ a candidate row from an outer query, _______ the inner query using candidate row value, and _______ values from the inner query to qualify or disqualify the candidate row. Mark for Review (1) Points CREATE; EXECUTE; USE DELETE; UPDATE; INSERT GET; EXECUTE; USE (*) ROLLUP; GRANT; DROP Correct 24. Oracle allows you to write named subqueries in one single statement, as long as you start your statement with the keyword WITH. True or False? Mark for Review (1) Points True (*) False Incorrect. Refer to Section 6 Lesson 4. 25. The Oracle server performs a correlated subquery when the subquery references a column from a table referred to in the parent. True or False? Mark for Review (1) Points True (*) False Incorrect. Refer to Section 6 Lesson 4. 26. Evaluate this SELECT statement: SELECT player_id, name FROM players WHERE team_id IN (SELECT team_id FROM teams WHERE team_id > 300 AND salary_cap > 400000); What would happen if the inner query returned a NULL value? Mark for Review (1) Points No rows would be returned by the outer query. (*)

A syntax error in the outer query would be returned. A syntax error in the inner query would be returned. All the rows in the PLAYER table would be returned by the outer query. Incorrect. Refer to Section 6 Lesson 3. 27. Which comparison operator would you use to compare a value to every value returned by a subquery? Mark for Review (1) Points SOME ANY ALL (*) IN Incorrect. Refer to Section 6 Lesson 3. 28. Examine the data in the PAYMENT table: PAYMENT_ID CUSTOMER_ID PAYMENT_DATE PAYMENT_TYPE 86590586 8908090 10-JUN-03 BASIC 859.00 89453485 8549038 15-FEB-03 INTEREST 596.00 85490345 5489304 20-MAR-03 BASIC 568.00 This statement fails when executed: SELECT customer_id, payment_type FROM payment WHERE payment_id = (SELECT payment_id FROM payment WHERE payment_amount = 596.00 OR payment_date = '20-MAR-2003'); Which change could correct the problem? Mark for Review (1) Points Change the outer query WHERE clause to 'WHERE payment_id IN'. (*) Remove the quotes surrounding the date value in the OR clause. Remove the parentheses surrounding the nested SELECT statement. Change the comparison operator to a single-row operator. Correct 29. Using a subquery in which clause will return a syntax error? for Review (1) Points Mark

PAYMENT_AMOUNT

WHERE FROM HAVING You can use subqueries in all of the above clauses. (*) Incorrect. Refer to Section 6 Lesson 1. 30. If you use the equality operator (=) with a subquery, how many values can the subquery return? Mark for Review (1) Points Only 1 (*) Up to 2 Up to 5 Unlimited Incorrect. Refer to Section 6 Lesson 1. Section 6 31. Which operator can be used with subqueries that return only one row? Mark for Review (1) Points LIKE (*) ANY ALL IN Correct 32. You need to display all the players whose salaries are greater than or equal to John Brown's salary. Which comparison operator should you use? Mark for Review (1) Points = > <= >= (*) Incorrect. Refer to Section 6 Lesson 1.

33. The TEACHERS and CLASS_ASSIGNMENTS tables contain these columns: TEACHERS TEACHER_ID NUMBER(5) Primary Key NAME VARCHAR2 (25) SUBJECT_ID NUMBER(5) CLASS_ASSIGNMENTS CLASS_ID NUMBER (5) Primary Key TEACHER_ID NUMBER (5) DATE MAX_CAPACITY NUMBER (3) All MAX_CAPACITY values are greater than 10. Which two SQL statements correctly use subqueries? (Choose two.) Mark for Review (1) Points (Choose all correct answers) SELECT * FROM class_assignments WHERE max_capacity = (SELECT AVG(max_capacity) FROM class_assignments); (*) SELECT * FROM teachers WHERE teacher_id = (SELECT teacher_id FROM teachers WHERE class_id = 45963); (*) SELECT * FROM teachers WHERE teacher_id = (SELECT teacher_id, class_assignments WHERE max_capacity > 0); SELECT * FROM teachers WHERE teacher_id LIKE (SELECT teacher_id FROM class_assignments WHERE max_capacity > 1000); SELECT * FROM class_assignments max_capacity = (SELECT AVG(max_capacity) FROM class_assignments GROUP BY teacher_id);

Correct 34. Examine the structures of the CUSTOMER and ORDER_HISTORY tables: CUSTOMER CUSTOMER_ID NUMBER(5) NAME VARCHAR2(25) CREDIT_LIMIT NUMBER(8,2)

OPEN_DATE DATE ORDER_HISTORY ORDER_ID NUMBER(5) CUSTOMER_ID NUMBER(5) ORDER_DATE DATE TOTAL NUMBER(8,2) Which of the following scenarios would require a subquery to return the desired results? Mark for Review (1) Points You need to display the date each customer account was opened. You need to display each date that a customer placed an order. You need to display all the orders that were placed on a certain date. You need to display all the orders that were placed on the same day as order number 25950. (*) Incorrect. Refer to Section 6 Lesson 1. 35. The EMPLOYEES and ORDERS tables contain these columns: EMPLOYEES EMPLOYEE_ID NUMBER(10) NOT NULL PRIMARY KEY FIRST_NAME VARCHAR2(30) LAST_NAME VARCHAR2(30) ADDRESS VARCHAR2(25) CITY VARCHAR2(20) STATE VARCHAR2(2) ZIP NUMBER(9) TELEPHONE NUMBER(10) ORDERS ORDER_ID NUMBER(10) NOT NULL PRIMARY KEY EMPLOYEE_ID NUMBER(10) NOT NULL FOREIGN KEY ORDER_DATE DATE TOTAL NUMBER(10) Which SELECT statement will return all orders generated by a sales representative named Franklin during the year 2001? Mark for Review (1) Points SELECT order_id, total FROM ORDERS (SELECT employee_id FROM employees WHERE last_name = 'Franklin') WHERE order_date BETWEEN '01-jan-01' AND '31-dec-01'; SELECT (SELECT employee_id FROM employees WHERE last_name = 'Franklin') AND order_id, total FROM ORDERS WHERE order_date BETWEEN '01-jan-01' AND '31-dec-01';

SELECT order_id, employee_id, total FROM ORDERS WHERE order_date BETWEEN '01-jan-01' AND '31-dec-01' AND emp_id = 'Franklin'; SELECT order_id, total FROM ORDERS WHERE employee_id = (SELECT employee_id FROM employees WHERE last_name = 'Franklin') AND order_date BETWEEN '01-jan-01' AND '31-dec-01'; (*)

Incorrect. Refer to Section 6 Lesson 1. 36. Which statement about subqueries is true? (1) Points Mark for Review

Subqueries should be enclosed in double quotation marks. Subqueries cannot contain group functions. Subqueries are often used in a WHERE clause to return values for an unknown conditional value. (*) Subqueries generally execute last, after the main or outer query executes. Incorrect. Refer to Section 6 Lesson 1.

Section 7 37. The STUDENTS table contains these columns: STU_ID NUMBER(9) NOT NULL LAST_NAME VARCHAR2 (30) NOT NULL FIRST_NAME VARCHAR2 (25) NOT NULL DOB DATE STU_TYPE_ID VARCHAR2(1) NOT NULL ENROLL_DATE DATE You create another table, named FT_STUDENTS, with an identical structure.You want to insert all full-time students, who have a STU_TYPE_ID value of "F", into the new table. You execute this INSERT statement: INSERT INTO ft_students (SELECT stu_id, last_name, first_name, dob, stu_type_id, enroll_date FROM students WHERE UPPER(stu_type_id) = 'F'); What is the result of executing this INSERT statement? Mark for Review (1) Points

All full-time students are inserted into the FT_STUDENTS table. (*) An error occurs because the FT_STUDENTS table already exists. An error occurs because you CANNOT use a subquery in an INSERT statement. An error occurs because the INSERT statement does NOT contain a VALUES clause. Incorrect. Refer to Section 7 Lesson 1. 38. Which statement about the VALUES clause of an INSERT statement is true? Mark for Review (1) Points If no column list is specified, then the values must be in the order the columns are specified in the table. (*) The VALUES clause in an INSERT statement is optional. Character, date, and numeric data must be enclosed within single quotes in the VALUES clause. To specify a null value in the VALUES clause, use an empty string (" "). Incorrect. Refer to Section 7 Lesson 1. 39. The PRODUCTS table contains these columns: PRODUCT_ID NUMBER NOT NULL PRODUCT_NAME VARCHAR2 (25) SUPPLIER_ID NUMBER NOT NULL LIST_PRICE NUMBER (7,2) COST NUMBER (5,2) QTY_IN_STOCK NUMBER(4) LAST_ORDER_DT DATE NOT NULL DEFAULT SYSDATE Which INSERT statement will execute successfully? Mark for Review (1) Points INSERT INTO products VALUES (2958, 'Cable', 8690, 7.09, 4.04, 700); (*) INSERT INTO products VALUES (2958, 'Cable', 8690, 7.09, 4.04, SYSDATE); INSERT INTO products(product_id, product_name) VALUES (2958, 'Cable'); INSERT INTO products(product_id, product_name, supplier_id VALUES (2958, 'Cable', 8690, SYSDATE);

Incorrect. Refer to Section 7 Lesson 1. 40. Assume all the column names are correct. The following SQL statement will execute which of the following? INSERT INTO departments (department_id, department_name, manager_id, location_id) VALUES (70, 'Public Relations', 100, 1700); Mark for Review (1) Points 100 will be inserted into the department_id column 1700 will be inserted into the manager_id column 70 will be inserted into the department_id column (*) 'Public Relations' will be inserted into the manager_name column Incorrect. Refer to Section 7 Lesson 1. Section 7 41. You want to enter a new record into the CUSTOMERS table. Which two commands can be used to create new rows? Mark for Review (1) Points INSERT, CREATE MERGE, CREATE INSERT, MERGE (*) INSERT, UPDATE Incorrect. Refer to Section 7 Lesson 2. 42. The PLAYERS table contains these columns: PLAYER_ID NUMBER NOT NULL PLAYER_LNAME VARCHAR2(20) NOT NULL PLAYER_FNAME VARCHAR2(10) NOT NULL TEAM_ID NUMBER SALARY NUMBER(9,2) You need to increase the salary of each player for all players on the Tiger team by 12.5 percent. The TEAM_ID value for the Tiger team is 5960. Which statement should you use? Mark for Review (1) Points UPDATE players (salary) SET salary = salary * 1.125; UPDATE players

SET salary = salary * .125 WHERE team_id = 5960; UPDATE players SET salary = salary * 1.125 WHERE team_id = 5960; (*) UPDATE players (salary) VALUES(salary * 1.125) WHERE team_id = 5960;

Incorrect. Refer to Section 7 Lesson 2. 43. Which two commands can be used to modify existing data in a database row? Mark for Review (1) Points (Choose all correct answers) DELETE MERGE (*) SELECT UPDATE (*) Incorrect. Refer to Section 7 Lesson 2. 44. One of the sales representatives, Janet Roper, has informed you that she was recently married, and she has requested that you update her name in the employee database. Her new last name is Cooper. Janet is the only person with the last name of Roper that is employed by the company. The EMPLOYEES table contains these columns and all data is stored in lowercase: EMPLOYEE_ID NUMBER(10) PRIMARY KEY LAST_NAME VARCHAR2(20) FIRST_NAME VARCHAR2(20) DEPARTMENT_ID VARCHAR2 (20) HIRE_DATE DATE SALARY NUMBER(10) Which UPDATE statement will accomplish your objective? Mark for Review (1) Points UPDATE employees SET last_name = 'cooper' WHERE last_name = 'roper'; (*) UPDATE employees last_name = 'cooper' WHERE last_name = 'roper';

UPDATE employees SET last_name = 'roper' WHERE last_name = 'cooper'; UPDATE employees SET cooper = 'last_name' WHERE last_name = 'roper';

Incorrect. Refer to Section 7 Lesson 2. 45. The TEACHERS and CLASS_ASSIGNMENTS tables contain these columns: TEACHERS TEACHER_ID NUMBER(5) NAME VARCHAR2(25) SUBJECT_ID NUMBER(5) HIRE_DATE DATE SALARY NUMBER(9,2) CLASS_ASSIGNMENTS CLASS_ID NUMBER(5) TEACHER_ID NUMBER(5) START_DATE DATE MAX_CAPACITY NUMBER(3) Which scenario would require a subquery to return the desired results? Mark for Review (1) Points You need to display the start date for each class taught by a given teacher. You need to create a report to display the teachers who were hired more than five years ago. You need to display the names of the teachers who teach classes that start within the next week. You need to create a report to display the teachers who teach more classes than the average number of classes taught by each teacher. (*) Correct 46. One of your employees was recently married. Her employee ID is still 189, however, her last name is now Rockefeller. Which SQL statement will allow you to reflect this change? Mark for Review (1) Points INSERT INTO my_employees SET last_name = 'Rockefeller' WHERE employee_ID = 189; INSERT my_employees SET last_name = 'Rockefeller' WHERE employee_ID = 189;

UPDATE INTO my_employees SET last_name = 'Rockefeller' WHERE employee_ID = 189; UPDATE my_employees SET last_name = 'Rockefeller' WHERE employee_ID = 189; (*) Correct 47. You need to delete a record in the EMPLOYEES table for Tim Jones, whose unique employee identification number is 348. The EMPLOYEES table contains these columns: EMPLOYEE_ID NUMBER(5) PRIMARY KEY LAST_NAME VARCHAR2(20) FIRST_NAME VARCHAR2(20) ADDRESS VARCHAR2(30) PHONE NUMBER(10) Which DELETE statement will delete the appropriate record without deleting any additional records? Mark for Review (1) Points DELETE FROM employees WHERE employee_id = 348; (*) DELETE FROM employees WHERE last_name = jones; DELETE * FROM employees WHERE employee_id = 348; DELETE 'jones' FROM employees;

Incorrect. Refer to Section 7 Lesson 2. 48. Evaluate this statement: DELETE FROM customer; Which statement is true? Mark for Review (1) Points The statement deletes all the rows from the CUSTOMER table. (*) The statement deletes the CUSTOMER column. The statement deletes the first row in the CUSTOMERS table. The statement removes the structure of the CUSTOMER table from the database.

Incorrect. Refer to Section 7 Lesson 2. 49. Examine the structures of the PRODUCTS and SUPPLIERS tables: SUPPLIERS SUPPLIER_ID NUMBER NOT NULL, Primary Key SUPPLIER_NAME VARCHAR2 (25) ADDRESS VARCHAR2 (30) CITY VARCHAR2 (25) REGION VARCHAR2 (10) POSTAL_CODE VARCHAR2 (11) PRODUCTS PRODUCT_ID NUMBER NOT NULL, Primary Key PRODUCT_NAME VARCHAR2 (25) SUPPLIER_ID NUMBER Foreign key to SUPPLIER_ID of the SUPPLIERS table CATEGORY_ID NUMBER QTY_PER_UNIT NUMBER UNIT_PRICE NUMBER (7,2) QTY_IN_STOCK NUMBER QTY_ON_ORDER NUMBER REORDER_LEVEL NUMBER You want to delete any products supplied by the five suppliers located in Atlanta. Which script should you use? Mark for Review (1) Points DELETE FROM products WHERE supplier_id IN (SELECT supplier_id FROM suppliers WHERE UPPER(city) = 'ATLANTA'); (*) DELETE FROM products WHERE UPPER(city) = 'ATLANTA'; DELETE FROM products WHERE supplier_id = (SELECT supplier_id FROM suppliers WHERE UPPER(city) = 'ATLANTA'); DELETE FROM suppliers WHERE supplier_id IN (SELECT supplier_id FROM suppliers WHERE UPPER(city) = 'ALANTA');

Incorrect. Refer to Section 7 Lesson 2. 50. What would happen if you issued a DELETE statement without a WHERE clause? Mark for Review (1) Points All the rows in the table would be deleted. (*) An error message would be returned.

No rows would be deleted. Only one row would be deleted. Incorrect. Refer to Section 7 Lesson 2.

You might also like