Finding Employees Who Have Been with the Company for More Than 5 Years

This technical problem deals with finding employees who have been with a company for more than 5 years. Given a table of data with employee start and end dates, the goal is to write a query that returns all employees who satisfy the 5-year criterion. An example input and output is provided.

Problem

Given a table of data with information on employee start and end dates, write a query to find all employees who have been with the company for more than 5 years.
Example input:
+-----+------------+------------+
| id  | start_date | end_date   |
+-----+------------+------------+
| 1   | 1/1/2010   | 12/31/2015 |
| 2   | 1/1/2011   | NULL       |
| 3   | 1/1/2012   | 12/31/2017 |
| 4   | 1/1/2013   | 12/31/2018 |
| 5   | 1/1/2014   | 12/31/2019 |
| 6   | 1/1/2015   | NULL       |
+-----+------------+------------+
Example output:
+-----+------------+------------+
| id  | start_date | end_date   |
+-----+------------+------------+
| 1   | 1/1/2010   | 12/31/2015 |
| 3   | 1/1/2012   | 12/31/2017 |
| 4 | 1/1/2013   | 12/31/2018 |
| 5   | 1/1/2014   | 12/31/2019 |
+-----+------------+------------+

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT * FROM table WHERE end_date - start_date > 5;

/*

The solution above is optimal because it is the most efficient way to find the employees who have been with the company for more than 5 years.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it is the most efficient way to find the employees who have been with the company for more than 5 years.

Evaluated at: 2022-11-27 14:16:12