当前位置:网站首页>MySQL de duplication query only keeps one latest record
MySQL de duplication query only keeps one latest record
2022-06-23 21:48:00 【dnbug Blog】
demand :MySQL De duplication query only keeps the latest record
Table structure and initial data are as follows SQL file :
-- MySQL dump 10.13 Distrib 8.0.28, for Linux (x86_64)
--
-- Host: localhost Database: test01
-- ------------------------------------------------------
-- Server version 8.0.28-0ubuntu0.20.04.3
/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
/*!40103 SET @[email protected]@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `MyClass`
--
DROP TABLE IF EXISTS `MyClass`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `MyClass` (
`id` int NOT NULL AUTO_INCREMENT,
`name` char(20) NOT NULL,
`sex` int NOT NULL DEFAULT '0',
`degree` double(16,2) DEFAULT NULL,
`inserttime` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `MyClass`
--
LOCK TABLES `MyClass` WRITE;
/*!40000 ALTER TABLE `MyClass` DISABLE KEYS */;
INSERT INTO `MyClass` VALUES (1,'Tom',0,96.45,'2022-02-19 18:00:00'),(2,'Joan',0,82.99,'2022-02-19 18:20:00'),(3,'Wang',0,96.59,'2022-02-19 18:30:00'),(4,'Tom',0,96.45,'2022-02-19 17:00:00'),(5,'Joan',0,82.99,'2022-02-19 18:25:00'),(6,'Wang',0,96.59,'2022-02-19 18:35:00');
/*!40000 ALTER TABLE `MyClass` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET [email protected]_TIME_ZONE */;
/*!40101 SET [email protected]_SQL_MODE */;
/*!40014 SET [email protected]_FOREIGN_KEY_CHECKS */;
/*!40014 SET [email protected]_UNIQUE_CHECKS */;
/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;
/*!40101 SET [email protected]_COLLATION_CONNECTION */;
/*!40111 SET [email protected]_SQL_NOTES */;
-- Dump completed on 2022-02-20 4:35:15
SQL Statistical statements :
# Full table scan query
SELECT * FROM test01.MyClass;
# according to 'name' Field de duplication statistics query latest data
SELECT * FROM test01.MyClass
WHERE
name in (SELECT name FROM test01.MyClass GROUP BY name)
AND inserttime in (SELECT max(inserttime) FROM test01.MyClass GROUP BY name);
Full table scan query _ result :
according to ’name’ Field de duplication statistics query latest data _ result :
边栏推荐
- Polar cycle graph and polar fan graph of high order histogram
- How to solve the loss of video source during easynvr split screen switching?
- Salesforce heroku (IV) application in salesforce (connectedapp)
- 个税怎么算?你知道吗
- One article to help you understand automatic injection
- Common commands for cleaning up kubernetes cluster resources
- Lightweight, dynamic and smooth listening, hero earphone hands-on experience, can really create
- Connect edgex gateway to thingsboard IOT platform
- Surprise! Edge computing will replace cloud computing??
- Who do you want to open a stock account? Is it safe to open an account online?
猜你喜欢

How to calculate individual income tax? You know what?

Outlook开机自启+关闭时最小化

Installation and use of Minio

Minimize outlook startup + shutdown

微信小程序中发送网络请求

个税怎么算?你知道吗

Sending network request in wechat applet

Smart cockpit SOC competition upgraded, and domestic 7Nm chips ushered in an important breakthrough

实验五 模块、包和库

How to improve the content quality of short video, these four elements must be achieved
随机推荐
Minimize outlook startup + shutdown
There is a 1GB difference between truncatememory and removememory
A detailed discussion on the use guide of network Swiss Army knife nmap
Arouter framework analysis
CAD图在线Web测量工具代码实现(测量距离、面积、角度等)
How do I clean the ECS hard disk? Why do I clean the hard disk regularly?
Improve efficiency, take you to batch generate 100 ID photos with QR code
小程序ssl证书过期是什么原因导致的?小程序ssl证书到期了怎么解决?
Sending network request in wechat applet
ECS (no matter which one, as long as it is an ordinary ECS) uses the installed version of SketchUp to install an error
How to solve the loss of video source during easynvr split screen switching?
Troubleshooting the problem that the channel cannot play after easycvr cascades to the upper platform
How to create cloud disk service how to create cloud disk service backup?
The transaction code mp83 at the initial level of SAP retail displays a prediction parameter file
HDLBits-> Circuits-> Arithmetic Circuitd-> 3-bit binary adder
Bcdedit, used to adjust the machine startup parameters (safe mode, BootMenu display name, CPU, memory, etc.)
Start optimization - directed acyclic graph
SAP retail wrmo replenishment monitoring
Explain the rainbow ingress universal domain name resolution mechanism
What are the advantages of attaching a virtual machine to a hard disk cloud server