问题
after selecting records i want to delete that records..i tried following query - (after removing ,MAX(value)
but its showing- You can't specify target table 'test' for update in FROM clause
DELETE FROM test WHERE ext_no IN
(
SELECT ext_no, MAX(value)
FROM test
GROUP BY ext_no
HAVING COUNT(*) > 2 AND
COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END)
);
回答1:
You can try below - you need to use subquery for inner select statement
DELETE FROM test WHERE ext_no IN
(
select ext_no from
(
SELECT ext_no, MAX(value)
FROM test
GROUP BY ext_no
HAVING COUNT(*) > 2 AND
COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END)
)t)
来源:https://stackoverflow.com/questions/53370339/mysql-query-to-delete-records-after-select