CS 275 Winter 2011 Problem Set 3

Similar documents
DUE: 9. Create a query that will return the average order total for all Global Fast Foods orders from January 1, 2002, to December 21, 2002.

DUE: CD_NUMBER TITLE PRODUCER YEAR 97 Celebrate the Day R & B Inc Holiday Tunes for All Tunes are US 2004

Database Programming - Section 7. Instructor Guide

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Additional Practice Solutions

Database Programming - Section 3. Instructor Guide

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Cartesian Product and the Join Operations. Copyright 2008, Oracle. All rights reserved.

Bsc (Hons) Software Engineering. Examinations for / Semester 1. Resit Examinations for BSE/15A/FT & BSE/16A/FT

Manipulating Data. Copyright 2004, Oracle. All rights reserved.

Database Programming with SQL

Intermediate SQL: Aggregated Data, Joins and Set Operators

GIFT Department of Computing Science. CS-217/224: Database Systems. Lab-5 Manual. Displaying Data from Multiple Tables - SQL Joins

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Database Design - Section 18. Instructor Guide

ÇALIŞMA TEST SORULARI

EXISTS NOT EXISTS WITH

Join, Sub queries and set operators

Data Manipulation Language

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

KORA. RDBMS Concepts II

Retrieving Data from Multiple Tables

School of Computing and Information Technology. Examination Paper Autumn Session 2017

Using the Set Operators. Copyright 2004, Oracle. All rights reserved.

Alkérdések II. Copyright 2004, Oracle. All rights reserved.

Oracle Database SQL Basics

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

Táblák tartalmának módosítása. Copyright 2004, Oracle. All rights reserved.

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Database Programming - Section 11. Instructor Guide

Database Programming - Section 1. Instructor Guide

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Database Programming - Section 18. Instructor Guide

CIS 207 Oracle - Database Programming and SQL HOMEWORK: # 13

GIFT Department of Computing Science. CS-217: Database Systems. Lab-4 Manual. Reporting Aggregated Data using Group Functions

Updating Column Values and Deleting Rows. Copyright 2008, Oracle. All rights reserved.

Assignment Grading Rubric

RESTRICTING AND SORTING DATA

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Testing Masters Technologies

Objectives. After completing this lesson, you should be able to do the following:

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

School of Computing and Information Technology Session: Spring CSCI835 Database Systems (Bridging Subject) Sample class test 23 July 2018

Introduction to Oracle9i: SQL

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Database Programming with SQL

HR Database. Sample Output from TechWriter 2007 for Databases

Oracle Database: SQL Fundamentals I. Oracle Internal & Oracle Academy Use Only. Volume II Student Guide. D64258GC10 Edition 1.0 January 2010 D65028

Working with Columns, Characters and Rows. Copyright 2008, Oracle. All rights reserved.

A. It executes successfully and displays rows in the descending order of PROMO_CATEGORY.

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

RETRIEVING DATA USING THE SQL SELECT STATEMENT

1Z0-007 ineroduction to oracle9l:sql

Sun Certified MySQL Associate

Database Programming with SQL

Creating Other Schema Objects

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

1Z Oracle Database 11g - SQL Fundamentals I Exam Summary Syllabus Questions

SQL Structured Query Language Introduction

Course Overview. Copyright 2010, Oracle and/or its affiliates. All rights reserved.

CONCAT SUBSTR LOWER (*) All three will be evaluated simultaneously. Correct

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH

Introduction to Oracle9i: SQL

SYSTEM CODE COURSE NAME DESCRIPTION SEM

Oracle Database 10g: SQL Fundamentals II

Database Programming with PL/SQL

Database Programming with SQL

Database Programming with SQL

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Key Points. COSC 122 Computer Fluency. Databases. What is a database? Databases in the Real-World DBMS. Database System Approach

Database Programming with SQL

Braindumps.1z QA

GIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Tables From Existing Tables

CS2 Current Technologies Lecture 2: SQL Programming Basics

BraindumpsVCE. Best vce braindumps-exam vce pdf free download

Oracle Syllabus Course code-r10605 SQL

Database Programming with SQL

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

Database Systems CSE 303. Outline. Lecture 06: SQL. What is Sub-query? Sub-query in WHERE clause Subquery

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Oracle 1Z Oracle Database 11g : SQL Fundamentals I. Download Full Version :

Exam code: Exam name: Database Fundamentals. Version 16.0

Conversion Functions

Oracle 1Z Oracle Database 11g SQL Fundamentals I. Download Full Version :

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

L e a r n S q l select where

Database Programming - Section 10. Instructor Guide

CS2 Current Technologies Lecture 3: SQL - Joins and Subqueries

Oracle MOOC: SQL Fundamentals

SELF TEST. List the Capabilities of SQL SELECT Statements

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

Database implementation Further SQL

COSC 122 Computer Fluency. Databases. Dr. Ramon Lawrence University of British Columbia Okanagan

Database Programming with PL/SQL

CS Reading Packet: "Views, and Simple Reports - Part 1"

Transcription:

CS 275 Winter 2011 Problem Set 3 Run the following quires in Oracle Application Express where appropriate. Cut and paste your query for each applicable question. For short answer or multiple choice type questions type your answer. Submit the answers to this problem set in the on-line drop box in the Folder marked ProblemSet3. 1. Using the three separate words "Oracle," "Internet," and "Academy," use one command to produce the following output: a. The Best Class b. Oracle Internet Academy 2. Write the query that displays the position of " I " in "Oracle Internet Academy"? 3. Starting with the string "Oracle Internet Academy", pad the string to produce Oracle$$$Internet$$$Academy 4. Using a substitution variable for the department name, write a query listing department id, department name and location id for departments located in the_department_of_your_choice. Use the DEPARTMENTS table. 5. Display Oracle database employee last_name and salary for employee_ids between 100 and 102. Include a third column that divides each salary by 1.55 and rounds the result to two decimal places. 6. Display employee last_name and salary for those employees who work in department 80. Give each of them a raise of 5.33% and truncate the result to two decimal places. 7. Divide each employee's salary by 3. Display only those employees last names who earn a salary that is a multiple of 3. 8. Display the days between the start of last summer's school vacation break and the day school started this year. Assume 30.5 days per month. Name the output "Days." 9. Using one statement, round today's date to the nearest month and nearest year and truncate it to the nearest month and nearest year. Use an alias for each column. 10. Display the number of years between the Global Fast Foods employee Bob Miller's birthday and today. Round to the nearest year. 11. The teacher said you have until the last day of this month to turn in your research paper. What day will this be? Name the output, "Deadline." 12. List the last names and birthdays of Global Fast Food Employees. Convert the birth dates to character data in the Month DD, YYYY format. Suppress any leading zeros. 13. Format a query from the Global Fast Foods f_promotional_menus table to print out the start_date of promotional code 110 as: The promotion began on the tenth of February 2004. 14. Ellen Abel is an employee who has received a $2,000 raise. Display her first name and last name, her current salary, and her new salary. Display both salaries with a $ and two decimal places. Label her new salary column AS New Salary.

15. Create a query that will format the DJ on Demand d_packages columns, low-range and high-range package costs, in the format $2500.00. 16. Create a report that shows the Global Fast Foods promotional name, start date, and end date from the f_promotional_menus table. If there is an end date, temporarily replace it with "end in two weeks." If there is no end date, replace it with today's date. 17. The manager of Global Fast Foods has decided to give all staff that currently do not earn overtime an overtime rate of $5.00. Construct a query that displays last names and overtime rate shown as $5.00. 18. For all null values in the specialty column in the DJs on Demand d_partners table, substitute "No Specialty." Show the first name and specialty columns only. 19. From the DJ on Demand d_songs table, create a query that replaces the 2-minute songs with "shortest" and the 10-minute songs with "longest." Label the output column "Play Times." 20. Use the Oracle database employees table and CASE expression to decode the department id. Display the department id, last name, salary and a column called "New Salary" whose value is based on the following conditions: If the department id is 10 then 1.25 * salary If the department id is 90 then 1.5 * salary If the department id is 130 then 1.75 * salary Otherwise, display the old salary. 21. Display the first name, last name, manager ID, and commission percentage of all employees in departments 80 and 90. Display the manager ID in an additional column called "Review." If they don't have a manager, display the commission percentage. If they don't have a commission, display 99999. 22. Create a Cartesian product that displays the columns in the d_play_list_items and the d_track_listings in the DJs on Demand database. 23. Correct the Cartesian product produced in question 1 by creating an equijoin using a common column. 24. Write a query to display the title, type description, and artist from the DJs on Demand database. 25. Using the Oracle database, create a query that returns the employee last name, salary, and job-grade level based on the salary. Select the salary between the lowest and highest salaries. 26. Create a query of the Oracle database that shows employee last names, department IDs, and department names. Include all employees even if they are not assigned to a department. 27. Modify the query in problem 2 to return all the department IDs even if no employees are assigned to them. 28. Display the employee's last name and employee number along with the manager's last name and manager number. Label the columns:

29. Display the names and hire dates for all employees who were hired before their managers, along with their managers' names and hire dates. Label the columns Employee, Emp Hired, Manager, and Mgr Hired, respectively. 30. Write a report that shows the hierarchy for Lex De Haans department. Include last name, salary and department id in the report. 31. Create a cross-join that displays the last name and department name from the employees and departments tables 32. Create a query that uses a natural join to join the departments table and the locations table by the location_id column. Display the department id and name, location id, and city. 33. Create a query that uses a natural join to join the departments table by the location_id column. Restrict the output to only department IDs of 20 and 50. Display the department id and name, location id, and city. 34. Join the Oracle database locations and departments table using the location_id column. Limit the results to location 1400 only. 35. Display country name, region ID and region name for Americas. 36. Write a statement that displays the employee ID, first name, last name, manager ID, manager first name, and manager last name for every employee in the employees table. Hint: this is a self-join. 37. Query and display manager ID, department ID, department name, first name, and last name for all employees in departments 80, 90, 110, and 190. 38. Display the employee's last name and employee number along with the manager's last name and manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively. Include employees that have no manager. Order the results by employee number. PART II 39. Create a query that will show the average cost of the DJ on Demand events. Round to two decimal places. 40. Find the average salary for Global Fast Foods staff members whose manager ID is 19. 41. How many songs are listed in the DJs on Demand D_SONGS table? 42. In how many different location types has DJs on Demand had venues?

43. Each of the following SQL queries has an error. Find the error and correct it. Use Oraacle Application Express to verify that your corrections produce the desired results. a. SELECT manager_id FROM employees WHERE AVG(salary) <16000 GROUP BY manager_id; b. SELECT cd_number, COUNT(title) FROM d_cds WHERE cd_number < 93; c. SELECT ID, MAX(ID), artist AS Artist FROM d_songs WHERE duration IN('3 min', '6 min', '10 min') HAVING ID < 50 GROUP by ID; d. SELECT loc_type, rental_fee AS Fee FROM d_venues WHERE id <100 GROUP BY "Fee" ORDER BY 2; 44. Write a query to display the manager_id, job_id, total salary. Include in the result the subtotal salary for each manager and a grand total of all salaries. 45. What DJs on Demand d_play_list_items song_id's have the same event_id as song_id 45? 46. Which events in the DJs on Demand database cost more than event_id = 100? 47. What is the staff type for those Global Fast Foods jobs that have a salary less than those of any Cook staff-type jobs? 48. Find the last names of all employees whose salaries are the same as the minimum salary for any department 49. Which Global Fast Foods employee earns the lowest salary? Hint: You can use either a single-row or a multiple-row subquery. 50. Using a WITH clause write a SELECT statement to list the job_title of those jobs whose maximum salary is more than half the maximum salary of the entire company. Name your subquery MAX_CALC_SAL. Name the columns in the result JOB_TITLE and JOB_TOTAL, and sort the result on JOB_TOTAL in descending order. 51. Write one query to return the employee_id, job_id, hire_date and department_id of all employees and a second query listing employee_id, job_id, start_date and department_id from the job_hist table and combine the results as one single output. Make sure you suppress duplicates in the output.

52. DJs on Demand just purchased four new CDs. Use an explicit INSERT statement to add each CD to the copy_d_cds table. After completing the entries, execute a SELECT * statement to verify your work. 53. DJs on Demand has two new events coming up. One event is a fall football party and the other event is a sixties theme party. The DJs on Demand clients requested the songs shown in the table for their events. Add these songs to the copy_d_songs table using an implicit INSERT statement. 54. Monique Tuttle, the manager of Global Fast Foods, sent a memo requesting an immediate change in prices. The price for a strawberry shake will be raised from $3.59 to $3.75, and the price for fries will increase to $1.20. Make these changes to the copy_f_food_items table. 55. Sue Doe has been an outstanding Global Foods staff member and has been given a salary raise. She will now be paid the same as Bob Miller. Update her record in copy_f_staffs.