-2

好的,所以我有一个看起来像的 php 数组

array('somehash' => 'someotherhash', 'somehash2' => 'someotherhash2');

这里 somehash = producthash 和 someotherhash = tohash

$db->query('UPDATE sometable SET status = '.self::STATUS_NOT_AVAILABLE.', towhere = '.self::TO_WHERE.', '.
                    .'tohash = WHEN or IF or ??? and how ?, '.
                    .'WHERE status = '.self::STATUS_AVAILABLE.'  AND '.
                    .'producthash IN (' . implode(',' , $prodarray) . ')') or $db->err(__FILE__,__LINE__);

所以在上面的查询中,我希望通过mysql 字段tohash从 php 数组中获取值producthash

就像是tohash = IF(producthash IN '.$prodarray.', $prodarray['producthash'] , whatever)

当然,上述 IF 不起作用,因为我没有 producthash 值$prodarray['producthash']

任何人都知道解决这个问题的方法,因为我在数组中有超过 1000 个值并且不想运行数千个更新

在这种情况下,INSERT INTO ON DUPLICATE KEY 是不可能的,因为此表唯一键基于 3 个字段,并且在执行此更新时我没有所有三个字段值。

4

1 回答 1

0

子查询?

UPDATE ...
WHERE ... producthash in (SELECT * FROM products)

只要您不从要更新的同一个表中进行选择,这将起作用 - 如果没有变通方法,mysql 不允许这样做。

于 2012-08-13T00:45:16.773 回答