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