Home > Backend Development > PHP Tutorial > mysql怎么统计前一天记录?时间存储模式是:time()的

mysql怎么统计前一天记录?时间存储模式是:time()的

WBOY
Release: 2016-06-13 10:29:30
Original
931 people have browsed it

mysql如何统计前一天记录?时间存储模式是:time()的
CREATE TABLE `bean` (
`usedate` varchar(12) default NULL,


统计bean数据库 日期字段为:usedate

这样写:
select * from bean where date(usedate) = date_sub(curdate(),interval 1 day);

但出错,提示为:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in


可能上面的mysql语句只能统计出Y-m-d hh:mm这样存储格式的时间,如果时间存储是time()的如1340508737,请问如果统计出前一天的记录?!
谢谢!


改成这样也不行:
select * from bean where to_char(usedate,'yyyy-mm-dd') = date_sub(curdate(),interval 1 day);


------解决方案--------------------

SQL code
SELECT * FROM `bean` WHERE FROM_UNIXTIME(`usedate`, '%Y-%m-%d') = DATE_SUB(CURDATE(), INTERVAL 1 DAY)<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template