mysql - 如何从 2 个重复行中只删除一行?
问题描述
我在表中有 2 行重复,我只想从中删除 1 行并保留另一行。我该怎么做?
解决方案
PostGres 代码可能有点不同,但这里有一个来自 TSQL 的示例,它使用 CTE 执行此操作:
; WITH duplicates
AS (
SELECT ServerName ,
ProcessName ,
DateCreated ,
RowRank = ROW_NUMBER() OVER(PARTITION BY ServerName, ProcessName, DateCreated ORDER BY 1)
FROM dbo.ErrorLog
)
DELETE e
FROM dbo.ErrorLog e
JOIN duplicates d
ON d.ServerName = e.ServerName
AND d.ProcessName = e.ProcessName
AND d.DateCreated = e.DateCreated
AND d.RowRank <> 1
推荐阅读
- kubernetes - level=error msg="无法创建服务:未找到子集"
- javascript - 如何在 javascript 中使用带有现有访问令牌的 Graph 工具包人员选择器?
- php - docker wordpress 图像中 ssh2_connect 中的未定义函数
- javascript - “this”不起作用并被称为函数
- c# - 无法获取 - 请求的资源上不存在“Access-Control-Allow-Origin”标头
- react-native - React Native Expo BackHandler 功能
- javascript - 如何使用 useEffect 使用 useSelector @redux/toolkit 从 redux 获取数据?
- python - 创建一个 django 模型,该模型将保留否则删除的(CASCADED)模型实例(如监视列表)
- python - 将 sys.argv 转换为 JSON(正则表达式仅匹配单个字母,无单词)
- cdo-climate - 如何使用 cdo 或任何其他软件添加时间维度和合并 TRMM 每日数据?