How does mysql query records for a period of time
Mysql query method for a period of time records: 1. Query records within N days, the code is [WHERE TO_DAYS(NOW()) – TO_DAYS(time field) <= N]; 2. Query today’s records, code It is [where date (time field) = date (now ())]. More related free learning recommendation: mysql tutorial (video) mysql query section Time recording method: Record within 24 hours (ie 86400 seconds) $sql=”SELECT video_id, count(id) as n FROM `rec_down` WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(add_time)<=86400 group by video_id order by n desc "; $sql="select a.id,a.title,b.n from video_info a,(".$sql.")b where a.id=b.video_id order by n desc limit 20"; Record within N days WHERE TO_DAYS(NOW()) – TO_DAYS(time field) <= N Today’s record where date(time field)=date(now()) or where to_days(time field) = to_days(now()); Query a week: select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time); Query One month: select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(column_time); pre>The query selects all records with date_col values within the last 30 days. mysql> SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) – TO_DAYS(date_col) <= 30; //It's really convenient, I used to write it by myself, but I didn't know it, so it failed. DAYOFWEEK(date) Returns the day of the week index of date (1 = Sunday, 2 = Monday,…