`

Delete Duplicated Row in SQL Server

 
阅读更多
1. Truncate NoDup table

2. Create CTE1 to get the max MyTime group by FileName and Month

TRUNCATE TABLE NoDup;

;WITH CTE1 AS
(SELECT FileName, Max(MyTime) AS MaxMyTime
FROM SourceTableDup
GROUP BY FileName, CONVERT(VARCHAR(10),MyTime,10))
3. Select the target columns from SourceTable

4. Join the CTE1 on FileName and MyTime

5. Insert into NoDup table

INSERT INTO NoDup
SELECT Col1, Col2, Col3
FROM SourceTableDup INNER JOIN CTE1 
ON SourceTableDup.FileName = CTE1.TargetFileName
AND SourceTableDup.MyTime = CTE1.MaxMyTime
6. Truncate source table

7. Insert into source table from NoDup table

TRUNCATE TABLE SourceTableDup;
INSERT INTO SourceTableDup
SELECT * FROM NoDup;
Reference:
 
 
分享到:
评论

相关推荐

    微软内部资料-SQL性能优化5

    In a nonclustered index, the leaf level contains each index key, plus a bookmark that tells SQL Server where to find the data row corresponding to the key in the index. A bookmark can take one of two ...

    判断EXCEl版本并存入数据库

    在IT行业中,处理数据是日常任务之一,而Excel和SQL Server常常是数据处理的重要工具。在本场景中,我们关注的是如何判断Excel文件的版本,将其数据导入到SQL Server数据库中,并确保数据的完整性和一致性。以下将...

    欧母龙Omron SYSMAC OPC Server V2 (Version2.60)

    Omron SYSMAC OPC Server V2 (Version2.60) (1) Scaling functions have been added. Linear scaling and second-root scaling are available. (2) OPC-DA2.0-compliant dead band has been supported. (3) The ...

    duplicated.zip

    例如,如果数据来源于SQL Server,我们可能需要使用`pyodbc`或`pymysql`等库连接数据库。如果是Excel文件,可能需要用到`openpyxl`或`xlrd/xlwt`等库。无论哪种情况,处理过程的核心都是使用Pandas的`drop_...

    Database Processing Fundamentals, Design, and Implementation (12th Edition).rar

    Using SQL in Microsoft SQL Server 2008 Using SQL in Oracle Database 11g Using SQL in Sun Microsystems MySQL 5.1 SQL Enhancements for Querying a Single Table Sorting the Results SQL WHERE Clause ...

    matlab导入excel代码-utl_numbering_unique_and_duplicated_values_in_data_fram

    matlab导入excel代码utl_numbering_unique_and_duplicated_values_in_data_frame 编号数据帧中的唯一值和重复值关键字:sas sql连接合并大数据分析宏oracle teradata mysql sas社区stackoverflow统计信息人工智慧AI ...

    PLSQL_Developer_9.0.5.1648

    * A duplicated user did not show role privileges in SQL statements when no new user name was provided * Object Browser double-click action and drag & drop action could not be defined for database ...

    计算机网络第六版答案

    Yes, these tasks can be duplicated at different layers. For example, error control is often provided at more than one layer. 23. The five layers in the Internet protocol stack are – from top to ...

    Find Reference 2 1.2.10

    Remember that one redundant reference may resulted in asset being duplicated in each assetbundles and increase AssetBundle build sizes (Animation / Texture / Audio duplication) or degrade performance...

    WPTools.v6.29.1.Pro

    + DeleteField now has optional "Contents" parameter to delete a certain field with contents + the text writer now understand the option -softlinebreaks to create a \n at the end of every line. In ...

    Find Reference 2

    Remember that one redundant reference may resulted in asset being duplicated in each assetbundles and increase AssetBundle build sizes (Animation / Texture / Audio duplication) or degrade performance...

    find duplicated files

    "find duplicated files"的主题涉及到计算机文件系统管理、数据优化和存储效率提升。以下是一些关于如何查找和处理重复文件的重要知识点: 1. **重复文件的定义**:在计算机中,重复文件是指具有相同内容但文件名...

    Professional Refactoring in C# & ASP.NET

    Ways to take advantage of the method extraction to eliminate duplicated code How to make code simpler, easier to modify, and more understandable All about object oriented theory and design patterns ...

    progress-maven-plugin:Maven Reactor 进展

    进度-maven-插件 Maven Reactor 进展 显示或通知 maven 构建的进度,特别是对于长时间的多模块构建 用法 : ... <artifactId>progress-maven-plugin <version>0.6 ... <goal>display-progress ...

    Optical bistability and multistability via amplitude and phase control in a Duplicated two-level system

    We investigate the optical bistability (OB) in a duplicated two-level system contained in a ring cavity. The atoms are driven by two orthogonally polarized fields with a relative phase. The OB ...

    Labview去处掉数组重复的元素

    this vi is capble to remove the duplicated elements in the labview array.

    Thinking in Pandas.pdf

    2. **数据导入与导出**:Pandas支持多种数据格式的读写,如CSV、Excel、SQL数据库等。书中会讲解如何使用Pandas的read_csv、read_excel等函数导入数据,以及to_csv、to_excel等函数导出数据。 3. **数据清洗**:在...

    Python 列表去重去除空字符的例子

    print(delete_duplicated_element(['python', 'r', 'r', 'g', 'g', 'g', 't', 'y', 'g', 'n'])) ``` #### 二、去除列表中的空字符 在处理文本数据时,列表中可能会出现空字符串或空字符,这会影响到后续的数据分析...

    BURNINTEST--硬件检测工具

    - Corrected a bug, where in rare cases, the result summary could be duplicated in a log file. - Updated license management, in an attempt to remove a rare crash on startup. Release 5.3 build 1012....

    ffmpeg 合并文件异常.txt

    https://stackoverflow.com/questions/44374790/ffmpeg-concat-protocol-error-found-duplicated-moov-atom-skipped-it https://stackoverflow.com/questions/42859528/merge-video-with-ffmpeg ffmpeg -y -i ...

Global site tag (gtag.js) - Google Analytics