This technical problem involves writing a SQL query to return the names of employees who have been with the company for more than 5 years.
Write a SQL query that returns the names of all the employees who have been with the company for more than 5 years. Example input: Employee table: +----+----------+------------+ | id | name | start_date | +----+----------+------------+ | 1 | John | 1/1/2010 | | 2 | Jane | 2/2/2011 | | 3 | Joe | 3/3/2012 | | 4 | Jack | 4/4/2013 | | 5 | Jil | 5/5/2014 | | 6 | Jill | 6/6/2015 | +----+----------+------------+ Example output: +----+----------+------------+ | id | name | start_date | +----+----------+------------+ | 1 | John | 1/1/2010 | | 2 | Jane | 2/2/2011 | | 3 | Joe | 3/3/2012 | +----+----------+------------+
SELECT * FROM Employee WHERE start_date < DATE_SUB(CURDATE(), INTERVAL 5 YEAR); /* The above solution is optimal because it uses the DATE_SUB function to subtract 5 years from the current date. This is optimal because it will always return the correct results, regardless of the current date. */
The candidate's solution is correct and uses an optimal approach.
Evaluated at: 2022-11-09 08:16:14