Mysql
 sql >> Database >  >> RDS >> Mysql

Come trovare i dati della scorsa settimana in MySQL

prova a sottrarre 1 da weekNo:

SELECT  studentID, 
        DATE_FORMAT(`date`, '%U') `WeekNo`,
        COUNT(studentID) totalMissed
FROM hw_homework he
WHERE DATE_FORMAT(`date`, '%U') = 
(SELECT MAX(DATE_FORMAT(NOW(), '%U')-1) 
 FROM hw_homework hi 
 WHERE hi.studentID = he.studentID)
GROUP BY studentID, DATE_FORMAT(`date`, '%U')