原数据:
想要的结果:
y 10-01
y 08-10
y 08-07
r 09-01
r 08-25
r 08-07
ss 08-18
ss 08-07
先对他们按时间排序,再分组,再对组内的数据按时间进行排序
建表语句:
DROP TABLE IF EXISTS testor
;
CREATE TABLE testor
(id
int(11) NOT NULL,name
varchar(255) DEFAULT NULL,crdate
datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- Records of testor
INSERT INTO testor
VALUES ('0', 'ss', '2017-08-18 09:07:42');
INSERT INTO testor
VALUES ('1', 'y', '2017-08-10 09:07:57');
INSERT INTO testor
VALUES ('2', 'r', '2017-08-07 09:08:06');
INSERT INTO testor
VALUES ('3', 'r', '2017-08-25 09:08:19');
INSERT INTO testor
VALUES ('4', 'r', '2017-09-01 09:08:33');
INSERT INTO testor
VALUES ('5', 'ss', '2017-08-07 09:08:53');
INSERT INTO testor
VALUES ('6', 'y', '2017-08-07 11:51:12');
INSERT INTO testor
VALUES ('7', 'y', '2017-10-01 11:51:23');