oracle midterm exam answers

7
CIS 211C Database Design and SQL - Oracle KEY Assigned: Lab 7 Due: October 17, 2006 1. Do the following “Try it/Solve it” exercises: i. Section 17 Lesson 1 Slide 10: #1 and 3 1. The manager of Global Fast Foods would like to send out coupons for the upcoming sale. He wants to send one coupon to each household. Create the SELECT statement that returns the customer last name and a mailing address. 1. SELECT DISTINCT last_name, address,city, state, zip FROM f_customers; 3. Sue, Bob, and Monique were the employees of the month. Using the f_staffs table, create a SELECT statement to display the results as shown in the Super Star chart to the right. 3. SELECT '***'||first_name ||'***'||first_name||'***' AS "Super Star" FROM f_staffs; Section 17 Lesson 1 Slide 11: #5 and 7 5. The owners of DJs on Demand would like a report of all items in their D_CDs table with the following column headings: Inventory Item, CD Title, Music Producer, and Year Purchased. Prepare this report. 5. SELECT cd_number AS "Inventory Item", title AS "CD Title", producer AS "Music Producer", year AS "Year Purchased" FROM d_cds 7. Global Fast Foods has decided to give all staff members a 5% raise. Prepare a report that presents the output as shown in the chart to the right.

Upload: zuzudeeia

Post on 21-Oct-2015

514 views

Category:

Documents


8 download

DESCRIPTION

Oracle midterm exam answers

TRANSCRIPT

Page 1: Oracle midterm exam answers

CIS 211C Database Design and SQL - Oracle KEYAssigned: Lab 7 Due: October 17, 2006

1. Do the following “Try it/Solve it” exercises:i. Section 17 Lesson 1 Slide 10: #1 and 3

1. The manager of Global Fast Foods would like to send out coupons for the upcoming sale. He wants to send one coupon to each household. Create the SELECT statement that returns the customer last name and a mailing address.

1. SELECT DISTINCT last_name, address,city, state, zipFROM f_customers;

3. Sue, Bob, and Monique were the employees of the month. Using the f_staffs table, create a SELECT statement to display the results as shown in the Super Star chart to the right.

3. SELECT '***'||first_name ||'***'||first_name||'***' AS "Super Star"FROM f_staffs;

Section 17 Lesson 1 Slide 11: #5 and 7

5. The owners of DJs on Demand would like a report of all items in their D_CDs table with the following column headings: Inventory Item, CD Title, Music Producer, and Year Purchased. Prepare this report.

5. SELECT cd_number AS "Inventory Item", title AS "CD Title", producer AS "Music Producer", year AS "Year Purchased"FROM d_cds

7. Global Fast Foods has decided to give all staff members a 5% raise. Prepare a report that presents the output as shown in the chart to the right.

EMPLOYEE LAST NAME CURRENT SALARY SALARY WITH 5% RAISE

7. SELECT last_name AS "EMPLOYEE LAST NAME", salary AS "CURRENT SALARY",salary * 1.05 AS "SALARY WITH 5% RAISE"FROM f_staffs

Section 17, Lesson 4 Slide 8: #1 and 2

1. Using the Global Fast Foods database, retrieve the customer’s first name, last name, and address for the customer whose ID is 456.

1. SELECT first_name, last_name, addressFROM f_customersWHERE Id = 456;

Page 2: Oracle midterm exam answers

CIS 211C Database Design and SQL - Oracle KEYAssigned: Lab 7 Due: October 17, 2006

2. Show the name, start date, and end date for Global Fast Foods' promotional item "ballpen and highlighter" giveaway.

2. SELECT name, start_date, end_date, give_awayFROM f_promotional_menusWHERE give_away = 'ballpen and highlighter';

Section 17, Lesson 4 Slide 9: #5

5. The manager of DJ on Demand would like a report of all the CD titles and years of CDs that were produced before 2000.

5. SELECT  title, yearFROM d_cdsWHERE year < 2000;

Section 17, Lesson 4 Slide 10: #8

For the next three questions, use the following table information:

TABLE NAME: studentsCOLUMNS: studentno NUMBER(6)fname VARCHAR2(12)lname VARCHAR(20)sex CHAR(1)major VARCHAR2(24)

8. Write a SQL statement that will display the student number (studentno) of any student who has a PE major in the table named students. Title the studentno column Student Number.

8. SELECT studentno AS “Student Number” (AS is optional)FROM studentsWHERE major = ‘PE’ ;   

Section 17, Lesson 4 Slide 11: #11

11. Write a SQL statement that lists the Global Fast Foods employees who were born before 1980.

11. SELECT  first_name, last_nameFROM f_staffsWHERE birthdate < '01-JAN-80';

Page 3: Oracle midterm exam answers

CIS 211C Database Design and SQL - Oracle KEYAssigned: Lab 7 Due: October 17, 2006

ii. Section 17, Lesson 5 Slide 11: #1 and 3

1. Display the first name, last name, and salary of all Global Fast Foods staff whose salary is between $5.00 and $10.00 per hour.

1. SELECT  first_name, last_name, salaryFROM f_staffsWHERE salary BETWEEN 5.00 and 10.00;

3. Using only the less than, equal, or greater than operators, rewrite the following query:

3. SELECT first_name, last_nameFROM f_staffsWHERE salary >= 20 and salary <=60;

iii. Section 17, Lesson 5 Slide 12: #6 and 8

6. Select all the Oracle database employees whose last names end with "s ." Change the heading of the column to read "Possible Candidates."

6. SELECT  last_name AS "Possible Candidates"FROM employeesWHERE last_name LIKE '%s';

8. Write a SQL statement that lists the songs in the DJs on Demand inventory that are type code 77, 12, or 1.

8. SELECT  titleFROM d_songsWHERE  type_code IN ( 77,12,1);

iv. Section 18, Lesson 1 Slide 8: #2 and 4

2. Display the last names of all Global Fast Foods employees who have "e" and "i" in their last names.

2. SELECT last_nameFROM f_staffsWHERE last_name LIKE '%e%' AND last_name LIKE '%i%';

4. Using the employees table, write a query to display all employees whose last names start with "D" and have "a" and "e" anywhere in their last name.

4. SELECT last_nameFROM employeesWHERE last_name LIKE 'D%a%e%' or last_name LIKE 'D%e%a';

Page 4: Oracle midterm exam answers

CIS 211C Database Design and SQL - Oracle KEYAssigned: Lab 7 Due: October 17, 2006

v. Section 18, Lesson 1 Slide 9: #5 and 7

5. In which venues did DJs on Demand have events that were not in private homes?

5. SELECT loc_typeFROM d_venuesWHERE loc_type NOT IN('Private Home');

7. Who am I?I was hired by Oracle after May 1998 but before June of 1999. My salary is less than $8000 a year and I have an "en" in my last name.

7. SELECT first_name, last_nameFROM employeesWHERE last_name LIKE '%en%' and salary < 8000 and hire_date BETWEEN '01-JUN-98' AND '31-MAY-99';Diana Lorentz

vi. Section 18, Lesson 2 Slide 7: #1 and 3

1. In the example below, assign the employee_id column the alias of "Number." Complete the SQL statement to order the results set by the column alias.

SELECT employee_id, first_name, last_nameFROM employees;

1. SELECT employee_id AS "Number", first_name, last_nameFROM employeesORDER BY "Number";

3. Order the DJ on Demand songs by descending title. Use the alias "Our Collection" for the song title.

3. SELECT title AS "Our Collection"FROM d_songsORDER BY title DESC;

Page 5: Oracle midterm exam answers

CIS 211C Database Design and SQL - Oracle KEYAssigned: Lab 7 Due: October 17, 2006

vii. Section 18, Lesson 2 Slide 8: #4

4. Write a SQL statement using the ORDER BY clause that could retrieve the information needed. Do not run the query.

Create a list of students who are in their first year of school. Include the first name, last name, student ID number, and parking place number. Sort the results alphabetically by student last name and then by first name. If more than one student has the same last name, sort each first name in Z to A order. All other results should be in alphabetical order (A to Z).

Answers:4. SELECT first_name, last_name, student_id, year_in_school, parking_spaceFROM studentsWHERE year_in_school = 1  ORDER BY last_name, first_name DESC;(exact syntax names will vary)