Original: http://www.open-open.com/code/view/1423207309170
Select * fromad_protrack_twhereTo_days (Crt_time)=To_days (now ());//today, when we do the test, I call this SQL and find that it is not the desired result. After trying to find that the ' Time field ' within the parentheses of the To_days function cannot be quoted, the converted quotation marks a null query yesterday's information record:Select * fromad_protrack_twhereTo_days (now ()) –to_days (Crt_time)<= 1to inquire about the information records for nearly 7 days:Select * fromad_protrack_twhereDate_sub (Curdate (), INTERVAL7 Day)<=date (crt_time); query information records for nearly 30 days:Select * fromad_protrack_twhereDate_sub (Curdate (), INTERVAL - Day)<=date (crt_time); query this month's information record:Select * fromad_protrack_twhereDate_format (Crt_time,'%y%m')=Date_format (Curdate (),'%y%m'); Query the information record for the previous January:Select * fromad_protrack_twherePeriod_diff (Date_format (now),'%y%m'), Date_format (Crt_time,'%y%m'))=1;
MySQL query today, yesterday, nearly 7 days, nearly 30 days, this month, last month data of SQL