当前位置:网站首页>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 :
边栏推荐
- Simple code and design concept of "back to top"
- What is the process of opening a mobile card account? Is online account opening safe?
- How to reduce snapshots
- Basic concepts and common methods of syntactic dependency analysis
- Go bubbling, cocktail, quick, insert sort
- How to batch generate video QR code
- Raid card with hardware knowledge (5)
- How to improve the content quality of short video, these four elements must be achieved
- Who do you want to open a stock account? Is it safe to open an account online?
- Aiot application innovation competition - get better code completion and jump experience with clion
猜你喜欢

Analysis of Alibaba cloud Tianchi competition -- prediction of o2o coupon
![Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text](/img/b1/71cc36c45102bdb9c06e099eb42267.jpg)
Harmonyos application development -- mynotepad[memo][api v6] based on textfield and image pseudo rich text

How to use the serial port assistant in STC ISP?

Data visualization: summer without watermelon is not summer

Experiment 5 module, package and Library

Sending network request in wechat applet

智能座舱SoC竞争升级,国产7nm芯片迎来重要突破

Introduction to scikit learn machine learning practice

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

Simple code and design concept of "back to top"
随机推荐
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
Supplementary usage of upload component in fusiondesign 1
Installation and use of Minio
Go language core 36 lectures (go language practice and application 27) -- learning notes
SAP Migo mobile type 311 attempts to determine the batch, and the system reports an error -batch determination not Po
Cloud native practice of meituan cluster scheduling system
Build DNS server in Intranet
Arouter framework analysis
I'm in Shenzhen. Where can I open an account? Is online account opening safe?
Open source C # WPF control library -newbeecoder UI usage guide (I)
手机卡开户的流程是什么?在线开户安全么?
What are the advantages of attaching a virtual machine to a hard disk cloud server
v-chart
[同源策略 - 跨域问题]
Find my information | Apple may launch the second generation airtag. Try the Lenz technology find my solution
How to download offline versions of Firefox and chrome
Explain the rainbow ingress universal domain name resolution mechanism
ACL2022 | MVR:面向开放域检索的多视角文档表征
Infrastructure splitting of service splitting
Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis