Delete from employee_salary
where emp_id in(
select emp_id from
employee_salary
group by emp_id,project,salary
having count(*)>1
);
ERROR 1093 (HY000): You can't specify target table 'employee_salary' for update in FROM clause
如何解决此问题以及此查询为何也在运行?
答案 0 :(得分:1)
这里的一个选项是将子查询包装在另一个子查询中:
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class RecordedSimulation extends Simulation {
val httpProtocol = http
.baseURL("baseURL")
.inferHtmlResources()
val headers_0 = Map(
"accept" -> "*/*",
"accept-encoding" -> "gzip, deflate, br",
"accept-language" -> "en-US,en;q=0.9",
"access-control-request-headers" -> "access-control-allow-origin,authorization,content-type",
"access-control-request-method" -> "GET",
"origin" -> "URL_LINK",
"user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36")
val headers_1 = Map(
"accept" -> "*/*",
"accept-encoding" -> "gzip, deflate, br",
"accept-language" -> "en-US,en;q=0.9",
"access-control-allow-origin" -> "*",
**"authorization" -> "Need to pass value from the terminal while running the gatling.sh",**
"content-type" -> "application/json",
"origin" -> "ORIGIN_URL",
"referer" -> "REFERER_URL",
"user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36")
这里的诀窍是DELETE e.*
FROM employee_salary e
WHERE e.emp_id IN (SELECT emp_id FROM (SELECT emp_id
FROM employee_salary
GROUP BY emp_id, project, salary
HAVING COUNT(*) > 1) x);
上的子查询将强制MySQL创建一个临时表,该表独立于x
上发生的删除。
答案 1 :(得分:1)
试试这个:
Delete from employee_salary
where emp_id in(
select * from (
select emp_id from
employee_salary
group by emp_id,project,salary
having count(*)>1 )
as alias
)
我正在更改结果集的名称,以便它可以正常工作。