简体   繁体   中英

SQL Query 3rd term date

INSERT INTO `empleado` VALUES ('100', 'Alfonso', '1999-11-22', '100', '11');
INSERT INTO `empleado` VALUES ('101', 'Encarna', '2001-11-12', '100', '15');
INSERT INTO `empleado` VALUES ('102', 'Paco', '1999-10-16', '101', '12');
INSERT INTO `empleado` VALUES ('103', 'Juan Carlos', '1999-01-12', '101', '10');

That's my Date Type ,I need to select some codes that got into the company in the 3rd term of 1999

"select nombre,coddep,fecha_ingreso from 
empleado where fecha_ingreso >1999;"

-that was my initial query, but it's wrong since it selects the name , cod and datetime >1999

SELECT nombre, coddep, fecha_ingreso
  FROM empleado
  WHERE YEAR(fecha_ingreso) = 1999 AND QUARTER(fecha_ingreso) = 3
;

This will fetch rows in the 3rd calendar quarter of 1999:

SELECT nombre, coddep, fecha_ingreso
FROM empleado
WHERE fecha_ingreso BETWEEN '1999-07-01' AND '1999-09-30'

If the field is DATETIME rather than DATE, change the second date to 1999-09-30 12:59:59

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM