SET sql_mode = ''; --不加这一条语句group by 会报错 ,加了又不太安全。建议再加个varchar类型的字段保存时间,加了字段后就不用FROM_UNIXTIME()函数了
select *,FROM_UNIXTIME(a.pay_time,"%Y-%m-%d") as ptime
FROM test a LEFT JOIN test b on
FROM_UNIXTIME(a.pay_time,"%Y-%m-%d") = FROM_UNIXTIME(b.pay_time,"%Y-%m-%d")
and a.id >= b.id GROUP BY a.id,a.pay_name,datas
HAVING count(b.id) <= 3 ORDER BY a.pay_time,a.id
1、首先要给pay_time加上索引。
2、按照时间从数据库中取出你需要的数据数量,select * from table where pay_time >=t1 and pay_time < t2 order by pay_time desc limit pageSize;
3、在前端对你的数据按照时间进行分组。
之后再对数据根据 ptime 进行分组就行了