"MySQL" queries about time, such as this month, this year, this quarter

Source: Internet
Author: User
Tags mysql query

--MySQL Query this quarter--TodaySelect *  fromTicket_order_detailwhereTo_days (Use_time)=To_days (now ());--7 DaysSELECT * fromTicket_order_detailwhereDate_sub (Curdate (), INTERVAL7  Day)<=Date (use_time)--nearly 30 daysSELECT * fromTicket_order_detailwhereDate_sub (Curdate (), INTERVAL -  Day)<=Date (use_time)--this monthSELECT * fromTicket_order_detailWHEREDate_format (Use_time,'%y%m')=Date_format (Curdate (),'%y%m' )--last monthSELECT * fromTicket_order_detailWHEREPeriod_diff (Date_format (now),'%y%m'), Date_format (Use_time,'%y%m') )=1#查询本季度数据Select *  from' Ticket_order_detail 'whereQUARTER (Use_time)=QUARTER (now ()); #查询上季度数据Select *  from' Ticket_order_detail 'whereQUARTER (Use_time)=QUARTER (Date_sub (now (), interval1QUARTER)); #查询本年数据Select *  from' Ticket_order_detail 'where  Year(Use_time)= Year(now ()); #查询上年数据Select *  from' Ticket_order_detail 'where  Year(Use_time)= Year(Date_sub (now (), interval1  Year));--querying data for the current weekSELECTName,submittime fromEnterpriseWHEREYearweek (Date_format (Submittime, '%Y-%M-%d '))=Yearweek (now ());--query last week's dataSELECTName,submittime fromEnterpriseWHEREYearweek (Date_format (Submittime, '%Y-%M-%d '))=Yearweek (now ())-1;--querying data for the current monthSelectName,submittime fromEnterprisewhereDate_format (Submittime, '%Y-%M ')=Date_format (now (), '%Y-%m ')--query data that is currently 6 months from nowSelectName,submittime fromEnterprisewhereSubmittimebetweenDate_sub (now (), interval6 Month) andNow ();--querying data for the previous monthSelectName,submittime fromEnterprisewhereDate_format (Submittime, '%Y-%M ')=Date_format (Date_sub (Curdate (), INTERVAL1 MONTH),’%Y-%m ')Select* from`User' Wheredate_format (Pudate, '%Y%M ')=Date_format (Curdate (), '%Y%m ');Select *  from User whereWeekOfYear (From_unixtime (Pudate, '%Y-%M-%d '))=WeekOfYear (now ())Select*Fromuserwheremonth (From_unixtime (pudate, '%Y-%M-%d '))=MONTH(now ())Select* from[User]whereyear (From_unixtime (pudate, '%Y-%M-%d '))= Year(now ()) Andmonth (From_unixtime (pudate, '%Y-%M-%d '))=MONTH(now ())Select* from[User]--Wherepudatebetween last day of the month--And the first day of next monthwhereDate (regdate)=curdate ();Select *  fromTestwhere  Year(regdate)= Year(Now ()) and Month(regdate)=Month(Now ()) and  Day(regdate)= Day(now ())SELECTDate (c_instime), curdate () from' T_score 'WHERE 1LIMIT0, -

"MySQL" queries about time, such as this month, this year, this quarter

Related Article

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.