· 10 years ago · Sep 09, 2016, 06:42 AM
1-- ----------------------------
2-- Table structure for t_ds
3-- ----------------------------
4DROP TABLE IF EXISTS `t_ds`;
5CREATE TABLE `t_ds` (
6 `id` bigint(64) NOT NULL AUTO_INCREMENT,
7 `deviceId` varchar(50) DEFAULT NULL,
8 `eventId` varchar(50) DEFAULT NULL,
9 `eventTime` bigint(64) DEFAULT NULL,
10 `logInfoId` bigint(64) DEFAULT NULL,
11 `statusCode` tinyint(1) DEFAULT NULL,
12 PRIMARY KEY (`id`),
13 UNIQUE KEY `index_ds` (`deviceId`,`eventId`)
14) ENGINE=InnoDB DEFAULT CHARSET=utf8;
15
16INSERT INTO t_ds(deviceId, eventId, eventTime, logInfoId, statusCode)
17SELECT deviceId, eventId, eventTime, id, statusCode FROM t_loginfo
18WHERE (deviceId, eventId, eventTime) in (
19 SELECT
20 deviceId, eventId, MAX(eventTime)
21 FROM
22 t_loginfo
23 GROUP BY deviceId, eventId
24)
25GROUP BY deviceId, eventId;
26
271. delete table 't_ds' , rebuild it.
282. run the SQL insert statement with limit *,*.
29
30limit 0,1: insert 1 row, total rows is 1, the last id is 1, the next id is 2;
31limit 1,2: insert 2 row, total rows is 3, the last id is 3, the next id is 5;
32limit 3,3: insert 3 row, total rows is 6, the last id is 7, the next id is 8;
33limit 6,4: insert 4 row, total rows is 10, the last id is 11, the next id is 15;
34limit 10,5: insert 5 row, total rows is 15, the last id is 19, the next id is 22;
35
361 2 3 5 6 7 8 9 10 11 15 16 17 18 19