sql >> Base de Datos >  >> RDS >> Mysql

Seleccionar datos entre dos fechas excluir algunos días

Tal vez empezar con esto...

SELECT p.OperaterID
     , p.OperationID
     , SUM(p.TotalProduced) TotalProduced
     , SUM(p.TotalProducedOperator) TotalProducedOp
     , CASE WHEN DAYOFWEEK(p.startdatetime) IN (1,7) THEN 'Normal working day' ELSE 'Weekend' END DayType
  FROM tblproduction p
 WHERE p.StartDateTime >= '2015-02-01 00:00:00' AND p.StartDateTime <= '2015-02-28 23:59:59'
   AND p.OperaterID = 10
   AND DATE(p.StartDateTime) NOT IN (SELECT HolidayDate FROM tblholidays)
 GROUP 
    BY p.OperaterID
     , p.OperationID
     , CASE WHEN DAYOFWEEK(p.startdatetime) IN (1,7) THEN 'Normal working day' ELSE 'Weekend' END