1. Description of the problem:
Use YEARWEEK ( 'time field') = YEARWEEK (NOW ()) - 1 to week screening data, calculates the wrong problem encountered when New Year's Eve.
eg:
As shown above, the current date is January 6 2020. Note icon on the date are: 2019-12-25,2020-1-1,2020-1-6
sql result of a function using the following yearweek
Clearly, the day should be 2020-1-1 2020-1-6 day in the last week, but use the results yearweek function calculated display 201,952 does not mean 202001-1.
2019-12-25 2020-1-1 week is calculated using yearweek function is not a problem.
2, a processing method:
使用YEARWEEK(DATE_SUB(NOW(),INTERVAL 7 DAY))代替YEARWEEK(NOW())-1
I.e., the current date is calculated by the number of weeks back YEARWEEK date 7 days
YEARWEEK ( 'Time field') = YEARWEEK (DATE_SUB (NOW (), INTERVAL 7 DAY))