I am working with a database that has the following fields:
create table Empleado(
nombre varchar(50) primary key ,
sueldo integer,
cod varchar(10),
fecha_ingreso date,
);
In this case the name is Primary Key because of the statement I'm working on . I have to be able to show only the records whose year of entry date is 2014 onwards, if I have the following records:
insert into Empleado(nombre,sueldo,cod,fecha_ingreso) values("Juan",1600,"P2","2016/7/05");
insert into Empleado(nombre,sueldo,cod,fecha_ingreso) values("Kevin",3200,"T4","2012/01/13");
insert into Empleado(nombre,sueldo,cod,fecha_ingreso) values("Gonzales",4680,"G7","2008/10/24");
It should only obtain the first records whose year of entry is 2016. Since we are talking about a Date field, I am not very clear how to identify employees with a date of entry greater than 2014 with a select . How could I deal with it?
One way you can do it is with the following query:
SELECT * FROM Empleado WHERE fecha_ingreso BETWEEN '2014-01-01' AND CURDATE();
I recommend you review the documentation on date handling, I hope I have helped youSince you indicate that you only want to show those that are greater than 2014 (a particular year), then what you could do is rely on a date function
YEAR()
and only use a ">" or "<" comparator.Another fact. In your code where you created the table, there is a small error and you are missing a comma.