1-Guided Activity Tryout

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

RETRIEVING DATA USING THE SQL SELECT STATEMENT – GUIDED ACTIVITY

-SOLUTIONS

1) How many unique departments have employees currently working inthem?

2) For employees who quit the organization, find out how many years the employees
were employed. Assume that the year consists of 365.25 days. Also retrieve the
EMPLOYEE_ID, JOB_ID, START_DATE, and END_DATE for these employees

3) Query the JOBS table and return a single expression of the form The Job Id for the
<job_title’s> job is: <job_id>. Take note that the job_title should have an apostrophe
and an “s” appended to it to read more naturally. A sample of this output for the
organization president is: “The Job Id for the President’s job is: AD_PRES.” Alias this
column expression as “Job Description” using the AS keyword.

RESTRICTING AND SORTING DATA


1) Retrieve a list of DEPARTMENT_NAME values that end with the three letters “ing”
and second character is “a” from the DEPARTMENTS table

2) Write a query that extracts the JOB_TITLE, MIN_SALARY, and MAX_SALARY


columns, as well as an expression called VARIANCE, which is the difference
between the MAX_SALARY and MIN_SALARY values, for each row. The result
should include only JOB_TITLE values that contain either the word “President” or
“Manager.” Sort the list in descending order based on the VARIANCE expression. If
more than one row has the same VARIANCE value, then, sort these rows by
JOB_TITLE in reverse alphabetic order.

3) A common computation performed by the Finance department relates to the


calculation of taxes levied upon an employee. The tax deducted per employee is
calculated by obtaining the annual salary for the employee and the current tax rate,
which may vary from year to year as per the regulations laid from the ministry of
finance. Write a reusable query for the current tax rate and for an employee_id as
input, return the EMPLOYEE_ID, FIRST_NAME, SALARY, ANNUAL
SALARY,TAX_RATE, and the TAX AMOUNT.
-26
USING SINGLE ROW FUNCTIONS TO CUSTOMIZE THE OUTPUT – GUIDED ACTIVITY

1) Retrieve a list of all FIRST_NAME and LAST_NAME values from the EMPLOYEES
table where FIRST_NAME contains the character string “li.”
2) Envelope printing restricts the addressee field to 16 characters. Ideally, the
addressee field contains employees’ FIRST_NAME and LAST_NAME values
separated by a single space. When the combined length of an employee’s
FIRST_NAME and LAST_NAME exceeds 15 characters, the addressee field should

Page 1 of 2
contain their formal name. An employee’s formal name is made up of the first letter of
their FIRST_NAME and the first 14 characters of their LAST_NAME. You are
required to retrieve a list of FIRST_NAME and LAST_NAME values and formal
names for employees where the combined length of FIRST_NAME and LAST_NAME
exceeds 15 characters.

3) Write a Query that displays the employee number, hire date, number of months
employed, six-month review date, first Friday after hire date, and the last day of the
hire month for all employees who have been employed for fewer than 150 months
and working for department 50

USING CONVERSION FUNCTIONS AND CONDITIONAL EXPRESSIONS – GUIDED


ACTIVITY
1) Retrieve a list of FIRST_NAME and LAST_NAME values and an expression based
on the HIRE_DATE column for employees hired on a Saturday. The expression must
be aliased as START_DATE and a HIRE_DATE value of 17-FEB-1996 must return
the following string:
Saturday, the 17th of February, One Thousand Nine Hundred Ninety-Six.
2) You are required to return a set of rows from the EMPLOYEES table with
DEPARTMENT_ID values of 100. The set must also contain FIRST_NAME and
LAST_NAME values and an expression aliased as NAME_LENGTHS. This
expression must return the string 'Different Length' if the length of the FIRST_NAME
differs from that of the LAST_NAME, else the string 'Same Length' must be returned.

3) You are requested to query the LOCATIONS table for rows with the value US in the
COUNTRY_ID column. An expression aliased as LOCATION_INFO is required to
evaluate the STATE_PROVINCE column values and returns different information as
per the following table. Sort the output based on the LOCATION_INFO expression.

If State _Province Is The Value Returned Is


Washington ‘Headquarters’
Texas Oil Wells
California City
New Jersey Stree)Address

Page 2 of 2

You might also like