我需要删除 2012 年之前创建的表 'people' 中属于酒店 id '1' 的记录,并且在相关表 'taskinstance' 中只有 1 条记录。这些表以这种方式相关:people.id = taskinstance.idClient。我想出了以下内容,这给了我一个语法错误。
DELETE people FROM taskinstance people
INNER JOIN
(SELECT *
FROM taskinstance
WHERE substring(people.dateCreated,1,4) < 2012 and people.idHotel = '1'
GROUP BY taskinstance.idClient
HAVING COUNT(*) = 1) taskinstance
ON people.id = taskinstance.idClient
如果我只想查看记录,以下工作:
SELECT *
FROM people
INNER JOIN taskinstance ON people.id = taskinstance.idClient
WHERE substring(people.dateCreated,1,4) < 2012 and people.idHotel = '1'
GROUP BY people.id
HAVING COUNT(1) = 1
谢谢你提供的所有帮助。