MySQL query today, yesterday, nearly 7 days, nearly 30 days, this month, last month data of SQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.