Sei sulla pagina 1di 9

Mohamed_Suez ABU FARIS

10G










2011
admin
HIO SUEZ
6/7/2011


2


: -

Practice 1

1. Initiate an iSQL*Plus session using the user ID and password provided by the instructor.

User_id : scott

Password: tiger



2. iSQL*Plus commands access the database.

True/False

True
3.The following SELECT statement executes successfully:
SELECT last_name, job_id, salary AS Sal
FROM employees;
True/False
. %100 : :3

4. The following SELECT statement executes successfully:
SELECT *
FROM job_grades;
True/False
4 :
.HR

5. There are four coding errors in the following statement. Can you identify them?
SELECT employee_id, last_name
sal x 12 ANNUAL SALARY
FROM employees;
5 : : 1 - ) , ( ) SAL x 12 ( 2 - ) X ( (*) 3 -
) SAL ( ) HR ( ) SALARY ( 4 - ) ALIAS ( ) ANNUAL
SALARY ( ) ANNUAL SALARY ( .

You have been hired as a SQL programmer for Acme Corporation. Your first task is to create
some reports based on data from the Human Resources tables.
6.Your first task is to determine the structure of the DEPARTMENTS table and its contents.
6 : SQL

.

; S DESC DEPARTMENT

3

4-- -;-=- '-'-- Q- >-~( ; - ;--~ '- J-- 4--,= --- _- ....
'--='- '----- -=- '-'-- --= =,-~- _-- =,~- ,-- >-~( --= Q- '----- _-V ,~'=-- _- ;-=- -
~=-- =--- _- J- ='~- -~=-- 4- _->-~ _-- ,~ J= ;~ ,-- - Q-- >-~('- _---- _-- .
1-Displaying Table Structure
2- Duplicate Rows
3- Selecting Specific Columns
4-
5
+ 100 * 12

DESC: descending order
'- -='-- ` _`- DEFAULT

.
-,-- 4--- '~ _ '->-~( SQl 4-- -;-=- '-'-- Q- >-~( ; - ;--~ '- J-- 4--,= --- _-
'--='- '----- -=- '-'-- --= =,-~- _-- =,~- ,-- >-~( --= Q- '----- _-V ,~'=-- _-
~=-- =--- _- J- ='~- -~=-- 4- _->-~ _-- ,~ J= ;~ ,-- - Q-- >-~('- _---- _--
Displaying Table Structure __
Duplicate Rows __
Selecting Specific Columns __
Using Arithmetic Operators __
5- Operator Precedence __
* 12 100
6- Using the ORDER BY Clause __
ASC: ascending order, default
_''-- _-'`' -='-- ``- -= ,-= - - '- _'= -,--' ,, -- .. '- -='-- ` _`-
-
-,-- 4--- '~ _ '->-~(
'--='- '----- -=- '-'-- --= =,-~- _-- =,~- ,-- >-~( --= Q- '----- _-V ,~'=-- _-
~=-- =--- _- J- ='~- -~=-- 4- _->-~ _-- ,~ J= ;~ ,-- - Q-- >-~('- _---- _--










5 - ....
___ .


,-''= . ASC: ascending order, default
_''-- _-'`' -='-- ``- -= ,-= - - '- _'= -,--' ,, --

4







AS
.
9- Concatenation Operator
10-
11-Limiting the Rows That Are Selected
SELECT last_name, job_id, salary,
FROM employees;
SELECT last_name, 12*salary*commission_pct
FROM employees;
SELECT last_name
FROM employees;
SELECT last_name "Name" , salary*12 "Annual Salary"
FROM employees;
7- Defining a Null Value __


8- Using Column Aliases __


...
Concatenation Operator ) ( __
Alternative Quote (q) Operator __
.---- -=- '-' '-- '-+=,- '- " , .=' '- '-`' ='- _ `- ` _ ....
Limiting the Rows That Are Selected __

SELECT last_name, job_id, salary, commission_pct
FROM employees;
SELECT last_name, 12*salary*commission_pct
FROM employees;
SELECT last_name AS name, commission_pct comm
FROM employees;
SELECT last_name "Name" , salary*12 "Annual Salary"






" "





.---- -=- '-' '-- '-+=,- '-


commission_pct
SELECT last_name, 12*salary*commission_pct
name, commission_pct comm
SELECT last_name "Name" , salary*12 "Annual Salary"

5

12- Character Strings and Dates
Comparison Conditions
Operator
Meaning
=
Equal to
>
Greater than
>=
Greater than or equal to
<
Less than
<=
Less than or equal to
<>
Not equal to
BETWEEN
...AND...
Between two values (inclusive)
IN(set) Match any of a list of values
LIKE Match a character pattern
IS NULL
Is a null value
Character Strings and Dates __
Comparison Conditions >-'- ( -'--- __
Meaning
Equal to
Greater than
Greater than or equal to
Less than
Less than or equal to
Not equal to
Between two values (inclusive)

Match any of a list of values

Match a character pattern
Is a null value



) >-'-

















6

-=--- _ ,--- -= = = ,,-''
% denotes zero or many characters.
_ denotes one character.



-`= -=--- ==`- % -,---' =` - _-'+-` -= = ,,-'' .. -=---
% denotes zero or many characters.
_ denotes one character.

-`= -=--- ==`-





7

-:
1- You need to determine the structure of the EMPLOYEES table.
The HR department wants a query to display the last name, job code,
hire date, and employee number for each employee, with employee
number appearing first. Provide an alias STARTDATE for the HIRE_DATE
column. Save your SQL statement to a file named lab_01_07.sql so that
you can disperse this file to the HR department.

2- The HR department needs a query to display all unique job codes
from the EMPLOYEES table.

3- The HR department has requested a report of all employees and their
job IDs. Display the last name concatenated with the job ID
(separated by a comma and space) and name the column Employee and
Title.
4- If you want an extra challenge, complete the following exercise:
To familiarize yourself with the data in the EMPLOYEES table,
create a query to display all the data from that table. Separate
each column output by a comma. Name the column title THE_OUTPUT.

5- The HR department needs your assistance with creating some queries.
Due to budget issues, the HR department needs a report that
displays the last name and salary of employees who earn more than
$12,000. Place your SQL statement in a text file named
lab_02_01.sql. Run your query.

6- Create a report that displays the last name and department number
for employee number 176.
7- The HR departments needs to find high-salary and low-salary
employees. Modify lab_02_01.sql to display the last name and salary
for any employee whose salary is not in the range of $5,000 to
$12,000. Place your SQL statement in a text file named
lab_02_03.sql.
8- Create a report to display the last name, job ID, and start date
for the employees with the last names of Matos and Taylor. Order
the query in ascending order by start date.
9- Display the last name and department number of all employees in
departments 20 and 50 in ascending alphabetical order by name.
10-Modify lab_02_03.sql to display the last name and salary of
employees who earn between $5,000 and $12,000 and are in department
20 or 50. Label the columns Employee and Monthly Salary,
respectively. Resave lab_02_03.sql as lab_02_06.sql. Run the
statement in lab_02_06.sql.

8

11-The HR department needs a report that displays the last name and
hire date for all employees who were hired in 1994.
12- Create a report to display the
employees who do not have a manager.
13-Create a report to display the last name, salary, and
commission of all employees who earn commissions. Sort data in
descending order of salary and commissions.
14-Display all employee last names in which the third letter of the name
is a.
The HR department needs a report that displays the last name and
hire date for all employees who were hired in 1994.

Create a report to display the last name and job title of all
employees who do not have a manager.
Create a report to display the last name, salary, and
commission of all employees who earn commissions. Sort data in
descending order of salary and commissions.
Display all employee last names in which the third letter of the name
The HR department needs a report that displays the last name and
hire date for all employees who were hired in 1994.
last name and job title of all
Create a report to display the last name, salary, and
commission of all employees who earn commissions. Sort data in
Display all employee last names in which the third letter of the name



9

Potrebbero piacerti anche