我试图将此mysql查询转换为在SQL上运行,但在连接时遇到一些语法问题。基本上我想要做的是根据DWH_DATE在重复行上将DWH_HISTO设置为1。因此应标记较旧的重复项。
这是我尝试过的
UPDATE MAG_L_D3.dbo.INSCRIPT
INNER JOIN
(SELECT MAX(DWH_DATE) as lastId, CODINS
FROM INSCRIPT
WHERE DWH_HISTO=0
GROUP BY CODINS
HAVING COUNT(*) > 1) duplic on duplic.CODINS = MAG_L_D3.dbo.INSCRIPT.CODINS
SET DWH_HISTO = 1
WHERE MAG_L_D3.dbo.INSCRIPT.DWH_DATE < duplic.lastId
答案 0 :(得分:4)
我相信这是您正在寻找的语法:
;WITH CTE as
(
SELECT *, row_number() over (partition by CODINS order by DWH_DATE desc)rn
)
UPDATE CTE
SET DWH_HISTO = 1
WHERE
rn > 1
and DWH_HISTO=0
答案 1 :(得分:3)
使用内部联接更新:
GET /_search
{"query" : {"match_all": {}}, "docvalue_fields" : ["filed_name"]}