創建表數據 CREATE TABLE `praise_info` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `pic_id` varchar(64) DEFAULT NULL COMMENT '圖片ID', `created_ti ...
創建表數據
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;