我已经尝试过使用之前问题的答案进行大量查询,但似乎无法使其发挥作用。
当我运行此查询时,我得到6个结果(这就是我想要的),第一个collun是想要更新的值
select ranks.rank,ranks.vad as ran,id.* from ideias id
inner JOIN
(
SELECT p.codigo as vad,
@curRank := @curRank + 1 AS rank
FROM ideias p
JOIN (SELECT @curRank := 0) r
where concat(DATE_FORMAT(p.data_envio,'%Y'),'-',DATE_FORMAT(p.data_envio,'%m'))='2016-09'
or concat(DATE_FORMAT(p.data_nova_chance,'%Y'),'-',DATE_FORMAT(p.data_nova_chance,'%m'))='2016-09'
and p.Nota is not null
ORDER BY p.Nota DESC , p.data_envio ASC, p.retorno_esperado ASC
) ranks ON ranks.vad = id.codigo
where id.Nota is not null
结果如下:
如果您查看字段rank
和codigo
,这是正确的,这是我想要的更新
但是,当我运行此查询时:
UPDATE ideias id
inner JOIN
(
SELECT p.codigo as vad, @curRank := @curRank + 1 AS rank
FROM ideias p
JOIN (SELECT @curRank := 0) r
where concat(DATE_FORMAT(p.data_envio,'%Y'),'-',DATE_FORMAT(p.data_envio,'%m'))='2016-09'
or concat(DATE_FORMAT(p.data_nova_chance,'%Y'),'-',DATE_FORMAT(p.data_nova_chance,'%m'))='2016-09'
and p.Nota is not null
ORDER BY p.Nota DESC , p.data_envio ASC, p.retorno_esperado ASC
) ranks ON ranks.vad = id.codigo
SET id.Posicao = ranks.rank
where id.Nota is not null
更新错误,请查看结果: