0

如何删除以下查询返回的记录?

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

我尝试使用“如果存在则删除”方法来删除记录,这要么是错误的,要么是我没有正确执行,因为它删除了表中的所有记录,而不仅仅是我的查询返回的记录。

谢谢

4

2 回答 2

3
DELETE FROM "Hobby List" HL WHERE HL.User IN (your query here)

这应该做得很好,我在其他场景中使用过很多次。

http://www.w3schools.com/sql/sql_in.asp

于 2012-10-06T01:33:02.077 回答
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

)
于 2012-10-06T01:33:36.580 回答