Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Lab Tasks:

1. Write a query to display the current date. Label the column Date.
SELECT SYSDATE FROM EMPLOYEE;

2. For each employee, display the employee ID number, last_name, salary, and salary increased
by 15% and expressed as a whole number. Label the column New Salary. Place your SQL
statement in a text file named lab3_2.sql. Run your query.
SELECT EMP_ID, LASTNAME, SALARY, ROUND(SALARY + (SALARY * 0.15), 0) AS
NEW_SALARY
FROM EMPLOYEE;

3. Modify your query lab3_2.sql to add a column that subtracts the old salary from the new
salary. Label the column Increase. Save the contents of the file as lab3_4.sql. Run the revised
query.
SELECT EMPNO, EMP_NAME, SALARY, (SALARY+(SALARY*0.15)) AS
NEW_SALARY, (SALARY+(SALARY*0.15))-SALARY AS INCREASE
FROM EMPLOYEE;

4. Write a query that displays the employee’s last names with the first letter capitalized and all
other letters lowercase and the length of the names, for all employees whose name starts with
J, A, or M. Give each column an appropriate label. Sort the results by the employees’ last
names.
SELECT INITCAP(LASTNAME) AS NAME, LENGTH(LASTNAME) AS LENGTH
FROM EMPLOYEE
WHERE LASTNAME LIKE 'J%' OR LASTNAME LIKE 'A%' OR LASTNAME LIKE 'M%'
ORDER BY LASTNAME;

5. For each employee, display the employee’s last 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. Note: Your results will differ.
Bahria University, Department of Computer Science Islamabad Campus Page 39

SELECT LASTNAME, ROUND(MONTHS_BETWEEN(SYSDATE-HIRING_DATE), 0) AS


MONTHS_WORKED
FROM EMPLOYEE
ORDER BY MONTHS_WORKED;

6. Write a query that produces the following for each employee: earns monthly but wants . Label
the column Dream Salaries.
SELECT EMP_NAME ||' earns $'||SALARY||' monthly but wants $'||SALARY*3 "Dream Salary"

FROM EMPLOYEE;

7. Create a query to display the last name and salary for all employees. Format the salary to be
15
SELECT LASTNAME, LPAD(SALARY, 15, ‘$’)
FROM EMPLOYEE;

For Example:

8. Display each employee’s last 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
similar to “Monday, the Thirty-First of July, 2000.”
SELECT LASTNAME, HIRE_DATE, TO_CHAR((NEXT_DAY(HIRE_DATE,
'Monday')) )),'fmday," the "ddspth "of" month,yyyy')
FROM EMPLOYEE;
9. For Example:

10. Display the last name, hire date, and day of the week on which the employee started. Label
the column DAY. Order the results by the day of the week starting with Monday.
SELECT LASTNAME, HIRE_DATE, TO_CHAR(HIRE_DATE,'Day') AS DAY
FROM EMPLOYEE
ORDER BY TO_CHAR(HIRE_DATE-1,'d');

You might also like