为什么我不能只删除sql server中的一行。
这是我的表和查询,请更正并给我解决方案。 感谢...
ID IdSuratKeluar Type KodePosition
FDBC015F-8DCB-44F2-956F-262A3FB379B6 CE7A98B8-7A98-45FC-A338-322BD8BE02BD 2 0041
656CBFFA-F279-461D-B1B8-61D07B348223 CE7A98B8-7A98-45FC-A338-322BD8BE02BD 2 0037
656CBFFA-F279-461D-B1B8-61D07B348225 CE7A98B8-7A98-45FC-A338-322BD8BE02BD 2 0037
我对SqlServer的查询:
DELETE SuratKeluarPermission where KodeJabatan In
( select Top(1) KodePosition from SuratKeluarPermission Where IdSuratKeluar='CE7A98B8-7A98-45FC- A338-322BD8BE02BD' and KodePosition='0037')
答案 0 :(得分:1)
这将从表中删除具有给定条件的随机行:
;WITH CTE as
(
SELECT Top(1) *
FROM SuratKeluarPermission
WHERE
IdSuratKeluar='CE7A98B8-7A98-45FC-A338-322BD8BE02BD' and
KodePosition='0037'
ORDER BY NEWID()
)
DELETE FROM CTE
免责声明:我无法看到哪个世界会有用
答案 1 :(得分:0)
;WITH CTE AS
(
Select SuratKeluarPermission ,KodeJabatan,ROW_NUMBER()OVER(PARTITION BY KodePosition ORDER BY (SELECT NULL) ) RN from SuratKeluarPermission
)
DELETE FROM CTE where RN > 1