如何删除以下查询返回的记录?
Select HL.User from "Hobby List" HL
INNER JOIN (Select SUBSTRING(Code,1,10) Code,Count(SUBSTRING(CODE,1,10))
AS Occurances from Patient where length(Patient.Code) > 10
Group By SUBSTRING(Code,1,10)
Having COUNT(SUBSTRING(Code,1,10)) > 1) P
on SUBSTRING(HL.User,1,10) = P.Code
Group By HL.User
我试图通过使用“如果存在的删除”方法删除记录,这种方法错误或者我没有正确执行,因为它删除了表中的所有记录而不是我查询返回的记录。 / p>
谢谢
答案 0 :(得分:3)
DELETE FROM "Hobby List" HL WHERE HL.User IN (your query here)
这应该做得很好,我在其他场景中已经使用了很多次。
答案 1 :(得分:2)
试试这个:
DELETE FROM 'Hobby List'
WHERE User IN
(
Select HL.User from "Hobby List" HL
INNER JOIN (Select SUBSTRING(Code,1,10) Code,Count(SUBSTRING(CODE,1,10))
AS Occurances from Patient where length(Patient.Code) > 10
Group By SUBSTRING(Code,1,10)
Having COUNT(SUBSTRING(Code,1,10)) > 1) P
on SUBSTRING(HL.User,1,10) = P.Code
Group By HL.User
)