Q:

Write a query in SQL to list the employee id, name, hire_date, current date and experience of the employees in ascending order on their experiences

0

Write a query in SQL to list the employee id, name, hire_date, current date and experience of the employees in ascending order on their experiences.

 emp_id | emp_name | job_name  | manager_id | hire_date  | salary  | commission | dep_id
--------+----------+-----------+------------+------------+---------+------------+--------
  68319 | KAYLING  | PRESIDENT |            | 1991-11-18 | 6000.00 |            |   1001
  66928 | BLAZE    | MANAGER   |      68319 | 1991-05-01 | 2750.00 |            |   3001
  67832 | CLARE    | MANAGER   |      68319 | 1991-06-09 | 2550.00 |            |   1001
  65646 | JONAS    | MANAGER   |      68319 | 1991-04-02 | 2957.00 |            |   2001
  67858 | SCARLET  | ANALYST   |      65646 | 1997-04-19 | 3100.00 |            |   2001
  69062 | FRANK    | ANALYST   |      65646 | 1991-12-03 | 3100.00 |            |   2001
  63679 | SANDRINE | CLERK     |      69062 | 1990-12-18 |  900.00 |            |   2001
  64989 | ADELYN   | SALESMAN  |      66928 | 1991-02-20 | 1700.00 |     400.00 |   3001
  65271 | WADE     | SALESMAN  |      66928 | 1991-02-22 | 1350.00 |     600.00 |   3001
  66564 | MADDEN   | SALESMAN  |      66928 | 1991-09-28 | 1350.00 |    1500.00 |   3001
  68454 | TUCKER   | SALESMAN  |      66928 | 1991-09-08 | 1600.00 |       0.00 |   3001
  68736 | ADNRES   | CLERK     |      67858 | 1997-05-23 | 1200.00 |            |   2001
  69000 | JULIUS   | CLERK     |      66928 | 1991-12-03 | 1050.00 |            |   3001
  69324 | MARKER   | CLERK     |      67832 | 1992-01-23 | 1400.00 |            |   1001
(14 rows)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

SELECT emp_id,
       emp_name,
       hire_date,
       CURRENT_DATE,
       age(CURRENT_DATE, hire_date) EXP
FROM employees
ORDER BY EXP ASC;

Sample Output:

 emp_id | emp_name | hire_date  |    date    |           exp
--------+----------+------------+------------+-------------------------
  68736 | ADNRES   | 1997-05-23 | 2018-02-01 | 20 years 8 mons 9 days
  67858 | SCARLET  | 1997-04-19 | 2018-02-01 | 20 years 9 mons 12 days
  69324 | MARKER   | 1992-01-23 | 2018-02-01 | 26 years 9 days
  69062 | FRANK    | 1991-12-03 | 2018-02-01 | 26 years 1 mon 29 days
  69000 | JULIUS   | 1991-12-03 | 2018-02-01 | 26 years 1 mon 29 days
  68319 | KAYLING  | 1991-11-18 | 2018-02-01 | 26 years 2 mons 13 days
  66564 | MADDEN   | 1991-09-28 | 2018-02-01 | 26 years 4 mons 3 days
  68454 | TUCKER   | 1991-09-08 | 2018-02-01 | 26 years 4 mons 23 days
  67832 | CLARE    | 1991-06-09 | 2018-02-01 | 26 years 7 mons 22 days
  66928 | BLAZE    | 1991-05-01 | 2018-02-01 | 26 years 9 mons
  65646 | JONAS    | 1991-04-02 | 2018-02-01 | 26 years 9 mons 29 days
  65271 | WADE     | 1991-02-22 | 2018-02-01 | 26 years 11 mons 7 days
  64989 | ADELYN   | 1991-02-20 | 2018-02-01 | 26 years 11 mons 9 days
  63679 | SANDRINE | 1990-12-18 | 2018-02-01 | 27 years 1 mon 14 days
(14 rows)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now