w3resource
SQL exercises

SQL exercises on employee Database: List the employees whose experience is more than 27 years

SQL employee Database: Exercise-21 with Solution

[An editor is available at the bottom of the page to write and execute the scripts.]

21. Write a query in SQL to list the employees whose experience is more than 27 years.

Sample table: employees


Pictorial Presentation:

SQL exercises on employee Database: List the employees whose experience is more than 27 years

Sample Solution:

SELECT *
FROM employees
WHERE EXTRACT(YEAR
              FROM age(CURRENT_DATE, hire_date)) > 27;

Sample Output:

 emp_id | emp_name | job_name | manager_id | hire_date  | salary  | commission | dep_id
--------+----------+----------+------------+------------+---------+------------+--------
  64989 | ADELYN   | SALESMAN |      66928 | 1991-02-20 | 1700.00 |     400.00 |   3001
  65271 | WADE     | SALESMAN |      66928 | 1991-02-22 | 1350.00 |     600.00 |   3001
  65679 | SANDRINE | CLERK    |      69062 | 1990-12-18 | 900.00  |            |   2001
(3 rows)

Practice Online


Sample Database: employee

employee database structure

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query in SQL to list all the employees whose designation is CLERK.
Next: Write a query in SQL to list the employees whose salaries are less than 3500.

What is the difficulty level of this exercise?