You are on page 1of 3

LAB EXERCISE 3

SAIFUL NAIM BIN NORAZMAN

2023368399
Select the ID, last name combines with the first name and salary for all the employees that have
ST_MAN as their job.

SQL: SELECT employee_id AS ID, CONCAT(CONCAT(last_name, ' '), first_name) AS full_name, salary

FROM employees

WHERE job_id = 'ST_MAN';

Ques�on 2 Do the SQL that displays the first 8 characters of employee’s last names and indicates their
salary with #. Each # represents two thousand dollars. Sort the salary in ascending order.

SQL: SELECT SUBSTR(last_name, 1, 8) AS lastname, RPAD('#', salary/2000, '#') AS salary

FROM employees

ORDER BY salary;
Ques�on 3 By using sub string function, find the department’s name that ends with ‘ng’.
SQL: SELECT department_name

FROM departments

WHERE SUBSTR(department_name, -2) = 'ng';

Ques�on 4 Find the length of employees’ first name that have been work more than 5 years in the
company.

SQL: SELECT LENGTH(first_name) AS first_name

FROM employees

WHERE MONTHS_BETWEEN(SYSDATE, hire_date) >= 60;

Ques�on 5 Find the number of months of working for each employee in department 80.
SQL: SELECT employee_id, first_name, last_name, ROUND(MONTHS_BETWEEN(SYSDATE, hire_date),
2) AS months_worked

FROM employees

WHERE department_id = 80;

You might also like