当前位置:网站首页>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 :
边栏推荐
- After easydss is configured with domain name / public IP, it will always prompt for troubleshooting problems that do not exist in the service
- Using barcode software to make certificates
- Explain the rainbow ingress universal domain name resolution mechanism
- Shanghai benchmarking enterprise · Schneider Electric visited benchmarking learning lean production, smart logistics supply chain and digital transformation
- Common commands for cleaning up kubernetes cluster resources
- Data visualization: summer without watermelon is not summer
- DM sub database and sub table DDL "optimistic coordination" mode introduction - tidb tool sharing
- Go language limits the number of goroutines
- How many of the five app automated test AIDS have you used?
- Connect edgex gateway to thingsboard IOT platform
猜你喜欢

Find My资讯|苹果可能会推出第二代AirTag,试试伦茨科技Find My方案

发现一个大佬云集的宝藏硕博社群!

Selenium批量查询运动员技术等级

How to improve the content quality of short video, these four elements must be achieved

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

Facing the problem of lock waiting, how to realize the second level positioning and analysis of data warehouse

Bluetooth chip | Renesas and Ti launch new Bluetooth chip, try Lenz st17h65 Bluetooth ble5.2 chip

Leetcode must review six lintcode (28348455116385)

Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)

Beitong G3 game console unpacking experience. It turns out that mobile game experts have achieved this
随机推荐
Improve efficiency, take you to batch generate 100 ID photos with QR code
Smart cockpit SOC competition upgraded, and domestic 7Nm chips ushered in an important breakthrough
Selenium batch query athletes' technical grades
Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)
Simple code and design concept of "back to top"
TDD development mode recommendation process
Minimize outlook startup + shutdown
What is the gold content of PMP certificate
How does the hybrid cloud realize the IP sec VPN cloud networking dedicated line to realize the interworking between the active and standby intranet?
The use of go unsafe
How to use smart cloud disk service differences between local disk service and cloud disk service
Unusual transaction code mebv of SAP mm preliminary level
小程序ssl证书过期是什么原因导致的?小程序ssl证书到期了怎么解决?
Start optimization - directed acyclic graph
Tencent cloud commercial password compliance solution appears at the 2021 high-end Seminar on commercial password application innovation
Analysis of visual analysis technology
Installation and use of Minio
How to improve the content quality of short video, these four elements must be achieved
To develop AI face comparison, how to output multiple faces with comparative similarity?
《scikit-learn机器学习实战》简介