我在下面的查询中按预期工作。并返回我需要删除的行。
SELECT * FROM tests WHERE e2e_product_id=407 AND test_name='PWBAR-FullBalance-Auth-TC1' AND
test_id<>(SELECT MAX(test_id)AS testid FROM tests WHERE test_name IN
(SELECT test_name FROM tests WHERE e2e_product_id=407 GROUP BY test_name HAVING COUNT(*) >1) AND e2e_product_id=407 GROUP BY test_name)
我刚刚将以上查询更改为删除语法,但它返回异常
Delete FROM tests WHERE e2e_product_id=407 AND test_name='PWBAR-FullBalance-Auth-TC1' AND
test_id<>(SELECT MAX(test_id)AS testid FROM tests WHERE test_name IN
(SELECT test_name FROM tests WHERE e2e_product_id=407 GROUP BY test_name HAVING COUNT(*) >1) AND e2e_product_id=407 GROUP BY test_name)
错误:
错误代码:1093您不能在更新中指定目标表“测试” FROM子句
如何使用上述方法删除数据。有线索吗?
答案 0 :(得分:0)
我认为您可以尝试-
Delete FROM tests
WHERE e2e_product_id = 407
AND test_name = 'PWBAR-FullBalance-Auth-TC1'
AND test_id <> (SELECT MAX_TEST_ID
FROM (SELECT test_name, MAX(test_id) MAX_TEST_ID
FROM tests
WHERE e2e_product_id = 407
GROUP BY test_name
HAVING COUNT(*) > 1) TEMP)
答案 1 :(得分:0)
将YOUR_KEY更改为密钥
DELETE FROM TESTS WHERE YOUR_KEY IN(
SELECT YOUR_KEY FROM tests WHERE e2e_product_id=407 AND test_name='PWBAR-FullBalance-Auth-TC1' AND
test_id<>(SELECT MAX(test_id)AS testid FROM tests WHERE test_name IN
(SELECT test_name FROM tests WHERE e2e_product_id=407 GROUP BY test_name HAVING COUNT(*) >1) AND e2e_product_id=407 GROUP BY test_name)
)