Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views5 pages

Midterm Lab Manual

Uploaded by

sabahcsgawd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Midterm Lab Manual

Uploaded by

sabahcsgawd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction

to Database
Lab Manual Midterm

American International
University-Bangladesh
Lab 01: Writing Basic SQL Statements

Objectives:

To extract data from the database, you need to use the Structured Query Language (SQL) SELECT
statement. You may need to restrict the columns that are displayed. This lesson describes all the SQL
statements that you need to perform these actions. You may want to create SELECT statements that can
be used time and time again. This lesson also covers the use of SQL*Plus commands to execute SQL
statements.

Topics to be discussed:

 Capabilities of SQL SELECT Statements


 Basic SELECT Statement
 Writing SQL Statements
 Executing SQL Statements
 Selecting All Columns, All Rows
 Arithmetic Expressions
 Arithmetic Operators
 Using Arithmetic Operators
 Operator Precedence
 Using Parentheses
 Null Values
 Column Aliases
 Concatenation Operator
 Literal Character Strings
 Duplicate Rows
 Displaying Table Structure

Exercise:

1. Write a query to display the name, department number for all employees.
2. Create a unique listing of all jobs that are in department 30.
3. Include the location of department 30 in the output.
4. Write a query to display the employee name, employee no of all employees who earn a
commission.
5. Display the employee name and department no for all employees who have an A in their name.
Lab 02: Restricting and Sorting Data

Objectives:

While retrieving data from the database, you may need to restrict the rows of data that are displayed or
specify the order in which the rows are displayed. This lesson explains the SQL statements that you will
use to perform these actions.

Topics to be discussed:

 Limiting Rows Using a Selection


 Limiting Rows Selected
 Using the WHERE clause
 Character Strings and Dates
 Comparison Operators
 Using the Comparison Operators
 Other Comparison Operators
 Logical Operators
 Rules of Precedence
 The ORDER BY Clause
 Default Ordering of Data
 Reversing the Default Order
 Sorting by Multiple Columns

Exercise:

1. Create a query to display the name and salary of employees earning more than $2850.
2. Create a query to display the employee name and department number for employee number
7566.
3. Display the employee name, job, and start date of employees hired between February 20,
1981, and May 1, 1981. Order the query in ascending order by start date.
4. Display the employee name and department number of all employees in departments 10 and
30 in alphabetical order by name.
5. Write a query to list the name and salary of employees who earn more than $1500 and are in
department 10 or 30. Label the columns Employee and Monthly Salary, respectively.
6. Display the name and hire date of every employee who was hired in 1982.
7. Display the name and job title of all employees who do not have a manager.
8. Display the name, salary, and commission for all employees who earn commissions. Sort data
in descending order of salary and commissions
Lab 03: Single-Row Function

Objective:

Functions make the basic query block more powerful and are used to manipulate data values. This is the
first of two labs that explore functions. You will focus on single-row character, number, and date
functions, as well as those functions that convert data from one type to another—for example,
character data to numeric.

Topics to be discussed:

 SQL Functions
 Types of SQL Functions
 Single-row Functions
 Types of Single-row Functions
 Nesting Functions
 DUAL

Exercise:
1. Write a query to display the current date. Label the column Date.
2. Display the employee number, name, salary, and salary increase by 15% expressed as a whole
number. Label the column New Salary.
3. Modify your previous query to add a column that will subtract the old salary from the new
salary. Label the column Increase. Rerun your query.
4. Display the employee’s name, hire date, and salary review date, which is the first Monday after
six months of service. Label the column REVIEW. Format the dates to appear in the format
similar to “Sunday, the Seventh of September, 1981.”
5. For each employee display the employee name and calculate the number of months between
today and the date the employee was hired. Label the column MONTHS_WORKED. Order your
results by the number of months employed. Round the number of months up to the closest
whole number.
6. Write a query that produces the following for each employee: <employee name> earns <salary>
monthly but wants <3 times salary>. Label the column Dream Salaries.
7. Write a query that will display the employee’s name with the first letter capitalized and all other
letters lowercase and the length of their name, for all employees whose name starts with J, A, or
M. Give each column an appropriate label.
8. Create a query that will display the employee name and commission amount. If the employee
does not earn commission, put “No Commission.” Label the column COMM.
9. Create a query that displays the employees’ names and indicates the amounts of their salaries
through asterisks. Each asterisk signifies a hundred dollars. Sort the data in descending order of
salary. Label the column EMPLOYEE_AND_THEIR_SALARIES.
Lab 04: Aggregate Function

Objective:

Aggregate functions return a single result row based on groups of rows, rather than on single rows.
Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly
used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a
queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select
list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these.
Oracle applies the aggregate functions to each group of rows and returns a single result row for each
group.

Topics to be discussed:

 Aggregate Functions
 Frequently Used Aggregate Functions
 GROUP BY clause
 HAVING clause

Exercise:

1. Find average, maximum, minimum salary of the employees.


2. Find average, maximum, minimum salary of the employees according to department number.
3. Find average, maximum, minimum salary of the employees according to job category.
4. Find the name of lowest paid manager. (Manager is not Job).
5. Find the location where maximum number of employee is located
6. Find out job group having highest amount of total salary. (Sal + comm)
7. Suppose you need to know the name and department no. of the employee who earns the highest
salary. Write a SQL query to return this information.

You might also like