Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Selecionar dados entre duas datas exclui alguns dias


Talvez comece com isso...
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