Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.Part I of the Semester 2 Mid Term Exam covers Sections 1-4, and the Review of Joins in Section 5, of Database Programming with SQL curriculum.

Section 1

1.You need to return a portion of each employee”s last name, beginning with the first character up to the fifth character. Which character function should you use? Mark for Review(1) Points

INSTR

TRUNC

SUBSTR (*)

CONCAT

Correct

2.You query the database with this SQL statement:SELECT LOWER(SUBSTR(CONCAT(last_name, first_name)), 1, 5) “ID”FROM employee;In which order are the functions evaluated? Mark for Review(1) Points

Single row functions can accept only one argument, but can return multiple values.

Single row functions cannot modify a data type.

Single row functions can be nested. (*)

Single row functions return one or more results per row.

Correct22. Which SQL Statement should you use to display the prices in this format: “$00.30″? Mark for Review(1) Points

SELECT TO_CHAR(price, ‘$99,900.99′)FROM product;(*)

SELECT TO_CHAR(price, ‘$99,911.99′)FROM product;

SELECT TO_CHAR(price, ‘$99,990.99′)FROM product;

SELECT TO_NUMBER(price, ‘$99,900.99′)FROM product;

Correct23. The EMPLOYEES table contains these columns:EMPLOYEE_ID NUMBER(9)LAST_NAME VARCHAR2 (25)FIRST_NAME VARCHAR2 (25)SALARY NUMBER(6)You need to create a report to display the salaries of all employees. Which script should you use to display the salaries in format: “$45,000.00″?Mark for Review(1) Points

SELECT TO_CHAR(salary, ‘$999,999′)FROM employees;

SELECT TO_NUM(salary, ‘$999,990.99′)FROM employees;

SELECT TO_NUM(salary, ‘$999,999.00′)FROM employees;

SELECT TO_CHAR(salary, ‘$999,999.00′)FROM employees;(*)

Correct24. All Human Resources data is stored in a table named EMPLOYEES. You have been asked to create a report that displays each employee’s name and salary. Each employee’s salary must be displayed in the following format: $000,000.00. Which function should you include in a SELECT statement to achieve the desired result? Mark for Review(1) Points

Conversion functions convert a value from one data type to another data type. (*)

Single-row functions manipulate groups of rows to return one result per group of rows.

CorrectSection 3 26. You need to provide a list of the first and last names of all employees who work in the Sales department who earned a bonus and had sales over $50,000. The company president would like the sales listed starting with the highest amount first. The EMPLOYEES table and the SALES_DEPT table contain the following columns:EMPLOYEESEMPLOYEE_ID NUMBER(10) PRIMARY KEYLAST_NAME VARCHAR2(20)FIRST_NAME VARCHAR2(20)DEPARTMENT_ID VARCHAR2(20)HIRE_DATE DATESALARY NUMBER(10)SALES_DEPTSALES_ID NUMBER(10) PRIMARY KEYSALES NUMBER(20)QUOTA NUMBER(20)MANAGER VARCHAR2(30)BONUS NUMBER(10)EMPLOYEE_ID NUMBER(10) FOREIGN KEYWhich SELECT statement will accomplish this task?Mark for Review(1) Points

Correct27. You have the following EMPLOYEES table:EMPLOYEE_ID NUMBER(5) NOT NULL PRIMARY KEYFIRST_NAME VARCHAR2(25)LAST_NAME VARCHAR2(25)ADDRESS VARCHAR2(35)CITY VARCHAR2(25)STATE VARCHAR2(2)ZIP NUMBER(9)TELEPHONE NUMBER(10)DEPARTMENT_ID NUMBER(5) NOT NULL FOREIGN KEYThe BONUS table includes the following columns:BONUS_ID NUMBER(5) NOT NULL PRIMARY KEYANNUAL_SALARY NUMBER(10)BONUS_PCT NUMBER(3, 2)EMPLOYEE_ID VARCHAR2(5) NOT NULL FOREIGN KEYYou want to determine the amount of each employee’s bonus, as a calculation of salary times bonus. Which of the following queries should you issue?Mark for Review(1) Points

Incorrect. Refer to Section 328. You need to create a report that lists all employees in department 10 (Sales) whose salary is not equal to $25,000 per year. Which query should you issue to accomplish this task? Mark for Review(1) Points

Correct29. What is produced when a join condition is not specified in a multiple-table query using Oracle proprietary Join syntax? Mark for Review(1) Points

A self-join

An outer join

An equijoin

A Cartesian product (*)

Correct30. You have two tables named EMPLOYEES and SALES. You want to identify the sales representatives who have generated $100,000, or more, in revenue. Which query should you issue? Mark for Review(1) Points

Correct34. The EMPLOYEE_ID column in the EMPLOYEES table corresponds to the EMPLOYEE_ID column of the ORDERS table. The EMPLOYEE_ID column in the ORDERS table contains null values for rows that you need to display.Which type of join should you use to display the data? Mark for Review(1) Points

Natural join

Self-join

Outer join (*)

Equijoin

Correct35. Using Oracle Proprietary join syntax, which two operators can be used in an outer join condition using the outer join operator (+)? Mark for Review(1) Points

Incorrect. Refer to Section 3Section 4 37. You need to join the EMPLOYEE_HIST and EMPLOYEES tables. The EMPLOYEE_HIST table will be the first table in the FROM clause. All the matched and unmatched rows in the EMPLOYEES table need to be displayed. Which type of join will you use? Mark for Review(1) Points

A cross join

An inner join

A left outer join

A right outer join (*)

Incorrect. Refer to Section 438. Which query represents the correct syntax for a left outer join? Mark for Review(1) Points

Correct40. Which of the following best describes a natural join? Mark for Review(1) Points

A join between two tables that includes columns that share the same name, datatypes and lengths (*)

A join that produces a Cartesian product

A join between tables where matching fields do not exist

A join that uses only one table

CorrectSection 4 41. Which statement about a natural join is true? Mark for Review(1) Points

Columns with the same names must have identical data types.

Columns with the same names must have the same precision and datatype. (*)

Columns with the same names must have compatible data types.

Columns with the same names cannot be included in the SELECT list of the query.

Correct42. You need to join two tables that have two columns with the same name, datatype and precision. Which type of join would you create to join the tables on both of the columns? Mark for Review(1) Points

Natural join (*)

Cross join

Outer join

Self-join

Correct43. The primary advantages of using JOIN ON is: (Select two) Mark for Review(1) Points (Choose all correct answers)

The join happens automatically based on matching column names and data types.

It will display rows that do not meet the join condition.

It permits columns with different names to be joined. (*)

It permits columns that don’t have matching data types to be joined. (*)

Correct44. For which condition would you use an equijoin query with the USING keyword? Mark for Review(1) Points

You need to perform a join of the CUSTOMER and ORDER tables but limit the number of columns in the join condition. (*)

The ORDER table contains a column that has a referential constraint to a column in the PRODUCT table.

The CUSTOMER and ORDER tables have no columns with identical names.

The CUSTOMER and ORDER tables have a corresponding column, CUST_ID. The CUST_ID column in the ORDER table contains null values that need to be displayed.

Incorrect. Refer to Section 445. You created the CUSTOMERS and ORDERS tables by issuing these CREATE TABLE statements in sequence:CREATE TABLE customers(custid varchar2(5),companyname varchar2(30),contactname varchar2(30),address varchar2(30),city varchar2(20),state varchar2(30),phone varchar2(20),constraint pk_customers_01 primary key (custid));CREATE TABLE orders(orderid varchar2(5) constraint pk_orders_01 primary key,orderdate date,total number(15),custid varchar2(5) references customers (custid));You have been instructed to compile a report to present the information about orders placed by customers who reside in Nashville. Which query should you issue to achieve the desired results?Mark for Review(1) Points

CorrectSection 5 47. Which statement about the GROUP BY clause is true? Mark for Review(1) Points

The first column listed in the GROUP BY clause is the most major grouping. (*)

The last column listed in the GROUP BY clause is the most major grouping.

The GROUP BY clause can contain an aggregate function.

A GROUP BY clause cannot be used without an ORDER BY clause.

Correct48. 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 (*)

Correct49. What is the best explanation as to why this SQL statement will NOT execute?SELECT department_id “Department”, AVG (salary)”Average”FROM employeesGROUP 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.

Correct50. What will the following SQL Statement do?SELECT job_id, COUNT(*)FROM employeesGROUP BY job_id;Mark for Review(1) Points

Displays all the employees and groups them by job.

Displays each job id and the number of people assigned to that job id. (*)