SQL Query to Find Employees Who Have Been with Company for More Than 5 Years

Write a SQL query to find employees who have been with a company for more than 5 years. The table to query has the following schema: (name, department, start_date). The query should return the (name, department, start_date) for each employee meeting the 5 year criteria.

Problem

Given a table with the following schema:
CREATE TABLE Employee (
name VARCHAR(255),
department VARCHAR(255),
start_date DATE
);
Write a SQL query that finds the employees who have been with the company for more than 5 years.
Example input:
name | department | start_date
John Smith | Marketing | 1/1/2010
Jane Doe | Sales | 2/1/2011
Mary Jane | Engineering | 4/1/2014
Example output:
name | department | start_date
John Smith | Marketing | 1/1/2010

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT name, department, start_date
FROM Employee
WHERE start_date < DATE_SUB(CURDATE(), INTERVAL 5 YEAR);

/*

This solution is optimal because it uses the DATE_SUB function to subtract 5 years from the current date, and then compares the start_date to that date.

*/

A.I. Evaluation of the Solution

This solution is correct and demonstrates a good understanding of SQL.

Evaluated at: 2023-01-29 00:15:32