How does mysql count the previous day's records? The time storage mode is: CREATETABLE 'bean' ('usedate' varchar (12) defaultNULL of time (). the date field of the bean database for statistics is: usedate, which is written as select * frombeanwheredate (usedate) = How Does dat mysql count the previous day's records? The time storage mode is: time ()
Create table 'bean '(
'Usedate' varchar (12) default NULL,
The date field of the bean database is usedate.
Write as follows:
Select * from bean where date (usedate) = date_sub (curdate (), interval 1 day );
But the error message is:
Warning: mysql_num_rows (): supplied argument is not a valid MySQL result resource in
Maybe the above mysql statement can only count the time in the format Y-m-d hh: mm. if the time is stored as time () such as 1340508737, can I count the records of the previous day ?!
Thank you!
This cannot be done either:
Select * from bean where to_char (usedate, 'yyyy-mm-DD') = date_sub (curdate (), interval 1 day );
------ Solution --------------------
SQL code
SELECT * FROM 'Bean' WHERE FROM_UNIXTIME ('usedate', '% Y-% m-% d') = DATE_SUB (CURDATE (), INTERVAL 1 DAY)