开发中经常会遇到,分组查询最新数据的问题,比如下面这张表(查询每个地址最新的一条记录):
sql如下:
——————————–Table structure for test——————————
DROP TABLE IF EXISTS`test`;CREATE TABLE`test` (
`id`int(11) NOT NULLAUTO_INCREMENT,
`name`varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`address`varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`create_time`timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY(`id`) USING BTREE
) ENGINE= InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT =Dynamic;——————————–Records of test——
版权声明:本文为weixin_33685869原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。