当前位置: 移动技术网 > IT编程>数据库>Mysql > MYSQL 时间轴数据 获取同一天数据的前3条

MYSQL 时间轴数据 获取同一天数据的前3条

2019年07月16日  | 移动技术网IT编程  | 我要评论

  创建表数据

create table `praise_info` (
`id` bigint(20) not null auto_increment comment 'id',
`pic_id` varchar(64) default null comment '图片id',
`created_time` datetime default current_timestamp comment '创建时间',
primary key (`id`),
key `pic_id` (`pic_id`) using btree
) engine=innodb auto_increment=3647 default charset=utf8 comment='图片表';

 

  添加数据省略

  时间轴前2条数据

select * from
(
select *, @num := if(@created_time = date_format(created_time, '%y-%m-%d'), @num := @num + 1, 1) as row_num,
@created_time := date_format(created_time, '%y-%m-%d') as axistime from praise_info
order by id desc
) as temp
where row_num < 3;

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网