MySQL query all data SQL statements for the day

Source: Internet
Author: User
Tags current time mysql query

MySQL query all the information of the day:

The code is as follows

SELECT * FROM Test where year (regdate) =year (now ()) and month (RegDate) =month (today ()) and Day (regdate) =day (now)

This is a bit cumbersome, but also a simple wording:

The code is as follows

SELECT * FROM table where date (regdate) = Curdate ();

Another way of writing has not been tested.

Query the records of the day

The code is as follows

SELECT * from Hb_article_view where to_days (hb_addtime) = To_days (now ())

The date () function Gets the day part, discards the time part, and then compares it to the current date.

Add: Data for this week, last week, month, month

Query current data for this week

The code is as follows

SELECT name,submittime from Enterprise WHERE yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ());

Query last week's data

The code is as follows

SELECT name,submittime from Enterprise WHERE yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ())-1;

Querying data for the current month

Select Name,submittime from Enterprise where Date_format (Submittime, '%y-%m ') =date_format (now (), '%y-%m ')

Query data from current 6 months

The code is as follows

Select Name,submittime from Enterprise where Submittime between Date_sub (now (), Interval 6 month) and now ();

Query last month's data

The code is as follows

Select Name,submittime from Enterprise where Date_format (Submittime, '%y-%m ') =date_format (Date_sub (), INTERVAL 1 MONTH), '%y-%m '

SELECT * from ' user ' where Date_format (pudate, '%y%m ') = Date_format (Curdate (), '%y%m ');

SELECT * from user where WeekOfYear (from_unixtime (pudate, '%y-%m-%d ')) = WeekOfYear (now ())

SELECT *

From user

where MONTH (From_unixtime (pudate, '%y-%m-%d ')) = MONTH (now ())

SELECT *

from [user]

Where year (From_unixtime (pudate, '%y-%m-%d ') = year (now ())

and MONTH (From_unixtime (pudate, '%y-%m-%d ')) = MONTH (now ())

SELECT *

from [user]

Where pudate between last day of last month

And the first day of next month

MySQL query how many seconds of data

The code is as follows

SELECT Count (*) as C, sum (if (Logusertype =2, Logusertype, 0))/2 as A, sum (if (Logusertype =3, Logusertype, 0))/ 3 as B

From Testlog WHERE Unix_timestamp (now ())-unix_timestamp (logendtime) <=30

The total number of records in the query in 30 seconds, LogUser equals 2, and the total number of records that LogUser equals 3.

if (Logusertype =2, Logusertype, 0) if Logusetype equals 2, add on the Logusertype, otherwise 0.

SUM (if (Logusertype =2, Logusertype, 0) adds Logusertype to the summation.

SUM (if (Logusertype =2, Logusertype, 0))/2 as A, divided by 2 is the number of statistics.

Unix_timestamp (now ()) calculates the number of seconds in the current time.

Unix_timestamp (Logendtime) calculates the number of logendtime seconds

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.