时间:2021-07-01 10:21:17 帮助过:6人阅读
1.0 创建测试
CREATE TABLE `logtest` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `msg` varchar(500) NOT NULL, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; insert into `logtest` (msg) values(‘bbbbbbbbbbbbb‘); select * from logtest;
1.1 表中所有数据
需求背景
按照时间升序在日志表中取出不msg不重复的前3条数据
select * from logtest where id in (select Max(id) from logtest group by msg) order by create_time asc limit 3;
SQL按照某一列数据去重并显示整行信息
标签:auto null arch innodb mit lock ODB sign incr