0

我试图根据其他问题找到答案,但我无法将逻辑实现为我的必要性。

我可以轻松获得所需的信息,但是我无法使用这些信息更新表格。

我使用以下查询选择了所有必要的值:

select `roleid`, 
(select count(`killerid`) from `kills` where `killerid`=`roleid`) as `kills`, 
(select count(`corpseid`) from `kills` where `corpseid`=`roleid`) as `deaths` 
from `characters`

因此,此查询返回角色的 ID 及其各自的杀戮和死亡人数。

现在,我需要知道:如何更新表“字符”,将“杀死”和“死亡”行设置为查询中的返回值?

感谢您的时间。

4

1 回答 1

1
UPDATE characters c 
  LEFT JOIN 
    ( SELECT killerid, count(*) as kill_num FROM kills GROUP BY killerid ) k1
  ON c.roleid = k1.killerID 
  LEFT JOIN
    ( SELECT corpseid, count(*) as death_num FROM kills GROUP BY corpseid ) k2
  ON c.roleid = k2.corpseID
SET c.kills = k1.kill_num, c.deaths = k2.death_num
于 2013-04-24T21:04:12.950 回答