MySQL Query day all data SQL statement

Source: Internet
Author: User

MySQL queries all information on the day:

SELECT * FROM Test where year (regdate) =year (now ()) and month (regdate) =month (now ()) and Day (regdate) =day (now ())
This is a bit of a chore and a simple notation:

SELECT * FROM table where date (regdate) = Curdate ();
The other way, not tested.
Check the day's records

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 compares it to the current date.
Added: Data for this week, last week, this month, and last month
Querying data for the current week

SELECT Name,submittime from the Enterprise WHERE Yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ());
Query last week's data

SELECT Name,submittime from the 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 that is currently 6 months from now

Select Name,submittime from Enterprise where Submittime between Date_sub (now (), Interval 6 month) and now ();
Querying data for the previous month

Select Name,submittime from Enterprise where Date_format (Submittime, '%y-%m ') =date_format (Date_sub (Curdate (), 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 (today ())
Select *
from [ User]
where pudate between last day of last month
and next month first day
MySQL query data in how many seconds

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 within 30 seconds, the total number of records LogUser equals 2, and the total number of records LogUser equals 3.
if (Logusertype =2, Logusertype, 0) if Logusetype equals 2, accumulate on Logusertype, otherwise add 0.
SUM (if (Logusertype =2, Logusertype, 0)) sums up the logusertype.
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 of the current time,
Unix_timestamp (Logendtime) calculates the number of seconds logendtime

Http://www.3lian.com/edu/2013/08-29/93024.html

MySQL Query day all data SQL statement

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.