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

Cómo encontrar datos de la semana pasada en MySQL

intente restar 1 de 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')