Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to re-retain the largest record in MySQL

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to re-retain the largest record in MySQL? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Take the user login log table as an example, take the device that the user recently logged in to

1 SET NAMES utf8mb4; 2 SET FOREIGN_KEY_CHECKS = 0; 3 4-5-Table structure for t_login_log 6-7 DROP TABLE IF EXISTS `tresume login` 8 CREATE TABLE `tlog login` (9 `id` int (11) NOT NULL AUTO_INCREMENT,10 `log id` int (11) NOT NULL COMMENT 'user ID',11 `device_ name` varchar (32) COLLATE utf8mb4_bin NOT NULL COMMENT' login device', 12 `login_ time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'login time', 13 PRIMARY KEY (`id`) 14) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin 15 16-17-Records of t_login_log18-19 BEGIN;20 INSERT INTO `tasking loginloginlog` VALUES (1, 1121, 'iPhone 6slots,' 2019-07-01 19 VALUES 20 VALUES') 21 INSERT INTO `tresume loginlog` VALUES (2, 2120, 'vivo x20,' 2019-06-28 16 vivo 21 VALUES 11'); 22 INSERT INTO `tweak loginloginlog` VALUES (3, 1607, 'huawei P30 VALUES,' 2019-07-04 19rig log 59'); 23 log log (4, 2120, 'vivo x20,' 2019-06-30 19INSERT INTO 2234') 24 INSERT INTO `tresume loginlog` VALUES (5, 2120, 'vivo x20,' 2019-07-04 19vivo 23vivo 07'); 25 INSERT INTO `tweeloginlog`loginlog` VALUES (6, 1121, 'iPad mini',' 2019-07-03 19vivo 23 VALUES'); 26 log log (7, 1607, 'iPhone 8 loginloginlog`log`) (7, 1607,' iPhone 8 loginlog` 2019-06-30 19INSERT INTO 2406') 27 INSERT INTO `tcm loginlog` VALUES (8, 1970, 'MI8',' 2019-07-03 19 COMMIT;29 25 SET FOREIGN_KEY_CHECKS 00'); 28 log 30 log = 1

Self-connect, take the latest record

1 SELECT * FROM t_login_log ORDER BY user_id;2 3 SELECT 4 t1.* 5 FROM t_login_log t16 LEFT JOIN t_login_log T2 ON t1.user_id = t2.user_id AND t1.login_time < t2.login_time 7 WHERE t2.id IS NULL

Effect.

The answer to the question about how to re-retain the largest record in MySQL is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report