Mysql分组查询获取每组最新一条数据

数据表

Mysql分组查询获取每组最新一条数据_第1张图片

测试sql 

CREATE TABLE `test11` (
  `id` int(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `type` int(11) DEFAULT NULL,
  `in_date` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of test11
-- ----------------------------
INSERT INTO `test11` VALUES ('2', '张三2', '2', '2022-08-20 16:43:21');
INSERT INTO `test11` VALUES ('3', '张三3', '3', '2022-08-20 16:43:22');
INSERT INTO `test11` VALUES ('4', '张三4', '1', '2022-08-20 16:44:24');
INSERT INTO `test11` VALUES ('5', '张三5', '2', '2022-08-20 16:4

你可能感兴趣的:(mysql,sql,数据库)