美文网首页
mysql查询前n天的数据

mysql查询前n天的数据

作者: simplehu | 来源:发表于2017-10-18 19:34 被阅读0次

假设数据表table中有个字段modifytime的类型为datetime类型或者TIMESTAMP类型

查询当天的数据

select * from table where to_days(modifytime) = to_days(now());

查询前n天的数据

select * from table where to_days(now()) – to_days(modifytime) <= n;

假设数据表汇总有个字段modifytime的类型为int(5)类型,则:

查询当天的数据

select * from table where date_format(from_UNIXTIME(modifytime),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d');

select * from table where to_days(date_format(from_UNIXTIME(modifytime),'%Y-%m-%d')) = to_days(now());

参考于:http://www.jb51.net/article/51597.htm

相关文章

网友评论

      本文标题:mysql查询前n天的数据

      本文链接:https://www.haomeiwen.com/subject/npweuxtx.html