Mysql
 sql >> Base de données >  >> RDS >> Mysql

Sélectionner des données entre deux dates exclure certains jours

Peut-être commencer par ça...

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