我相信这会导致5分钟到20分钟的延迟,具体取决于记录的数量。我需要将其转换为LEFT JOIN,但需要一些帮助才能实现。
qry_arr = array(':bill_type' => "INT");
$sql = "update ".$billing_table." c set c.bill_type = :bill_type";
$sql .= " WHERE NOT EXISTS (SELECT s.abbreviation FROM state s WHERE s.abbreviation = c.out_location)";
$sql .= " and c.out_location != 'UNKNOWN' and c.out_location != ''";
答案 0 :(得分:1)
UPDATE $billing_table c
LEFT JOIN state s ON s.abbreviation = c.out_location
SET c.bill_type = :bill_type
WHERE s.abbreviation IS NULL
AND c.out_location NOT IN ('UNKNOWN', '')
对于与不匹配的行,这基本上与SELECT
的语法相同。参见Return row only if value doesn't exist。只需将SELECT ... FROM
替换为UPDATE
,然后在SET
之前插入WHERE
子句。
确保在out_location
和abbreviation
上有索引。