Mysql 删除局部变量部分工作的行

Mysql delete rows with local var working partially

我有三个 table:utenti、giocate 和 giocatori。

我必须删除 giocatori 和 giocate tables 中具有特定 ID 的行。

我是这样获取id的:

SELECT
    @ids:=giocate.id
  FROM
    giocate
  JOIN
    utenti ON utenti.id = giocate.id_account
  WHERE
    utenti.id = 642 AND DATE_FORMAT(giocate.time,
    '%Y-%m-%d') = '2016-03-20';

这有效,实际上

SELECT @ids;

给我

ids
-------
1225
4545
5454
6653
...

但是当我调用这个查询时:

DELETE giocate.*, giocatori.*
FROM
  giocatori
INNER JOIN
  giocate
WHERE
  giocate.id_giocatore = giocatori.id AND giocate.id IN (@ids)

我在每个 table 中只被删除一行... 所以我必须对 "count(@ids)" 重复该查询... 这是为什么?

安排。你不需要变量。这可能就足够了:

DELETE ge, gi
FROM giocatori gi INNER JOIN
     giocate ge
     ON gi.id_giocatore = ge.id 
WHERE ge.id_account = 642
       date(ge.time) = '2016-03-20';

这似乎抓住了你的逻辑意图。但是,如果您的数据结构可能的话,它可能会丢失 giocate 其他日期的记录。