Mysql queries all information of the current day: the code is as follows: select * fromtestwhereyear (regdate) year (now () andmonth (regdate) month (now () andday (regdate) day (now () is tedious and easy to write: The Code is as follows: select * fromtablewheredate (regdate) curdate ()
Mysql queries all information of the current day: the code is as follows: select * from test where year (regdate) = year (now () and month (regdate) = month (now ()) and day (regdate) = day (now () is tedious and easy to write: The Code is as follows: select * from table where date (regdate) = curdate ()
Mysql queries all information on the current day:
The Code is as follows:
Select * from test where year (regdate) = year (now () and month (regdate) = month (now () and day (regdate) = day (now ())
This is complicated and easy to write:
The Code is as follows:
Select * from table where date (regdate) = curdate ();
Another method is not tested.
Query records of the current day
The Code is as follows:
Select * from hb_article_view where TO_DAYS (hb_AddTime) = TO_DAYS (NOW ())
The date () function gets the date part, discards the time part, and then compares it with the current date.
Supplement: data for this week, last week, this month, and last month
Query data for the current 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;
Query data of the current month
Select name, submittime from enterprise where date_format (submittime, '% Y-% m') = date_format (now (),' % Y-% m ')
Query data 6 months from the current time
The Code is as follows:
Select name, submittime from enterprise where submittime between date_sub (now (), interval 6 month) and now ();
Query data of last month
The Code is as follows:
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 (now ())
Select *
From [user]
Where pudate between last day of last month
And the first day of next month
How many seconds does mysql query 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
Query the total number of records within 30 seconds. The total number of records whose loguser is equal to 2 and the total number of records whose loguser is equal to 3.
If (logusertype = 2, logusertype, 0) if logusetype is equal to 2, it is accumulated on logusertype; otherwise, 0 is added.
Sum (if (logusertype = 2, logusertype, 0) to accumulate all logusertypes.
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 of logendtime
,