Home > Backend Development > PHP Tutorial > mysql取表中《最新》三天的记录,sql语句怎么写

mysql取表中《最新》三天的记录,sql语句怎么写

WBOY
Release: 2016-06-23 14:10:15
Original
1009 people have browsed it

mysql取表中 最新三天的记录,sql语句怎么写。从网上查了一条,但这是 以当前时间为起点取最近几天的记录select * from rewards where DATE_SUB(CURDATE(), INTERVAL 4 DAY)
 


回复讨论(解决方案)

那么你说参照点应是什么呢?

最新三天是今天、昨天和前天。按照当前时间向后推3天进行过滤。

$startDate=date('Y-m-d',strtotime("-29 days"));
$endDate=date('Y-m-d');
$sql="select * from rewards  createTime>='".$start." 00:00:00' and createTime

那么你说参照点应是什么呢? 比方说今天是5月14号,表中的数据day只有到五月10号的,我本意是想取出8、9、10三天的,如果是以14号为参照点往前取三天的,取的是12、13、14三天的(没数据),就没法满足要求吧

最新三天是今天、昨天和前天。按照当前时间向后推3天进行过滤。 看四楼

try

select * from tt inner join(select date(day) as `day` from tt group by date(`day`) order by `day` desc limit 3) aon date(tt.day)=a.day
Copy after login
Copy after login

try

select * from tt inner join(select date(day) as `day` from tt group by date(`day`) order by `day` desc limit 3) aon date(tt.day)=a.day
Copy after login
Copy after login
这个查询的结果没有按照日期倒序排列啊怎么回事?

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