我有005_my_sc表,列
pdb_id listing_type
1 new
2 sale
3 rent
我也有005_my_cl表,列
pdb_id listing_type
1 0
2 0
3 0
我想用以下条件更新005_my_cl表
这是我正在尝试的:
update 005_my_sc old, 005_my_cl new1
set new1.listing_type = 2
where old.pdb_id = new1.pdb_id and old.listing_type = 'new'
代码没有语法错误,但没有任何改变,我错过了什么???
答案 0 :(得分:1)
你可以试试这个,交配:
UPDATE 005_my_sc t1
INNER JOIN 005_my_cl t2 ON t2.pdb_id = t1.pdb_id
SET t2.listing_type = (
CASE t1.listing_type
WHEN 'new' THEN 2
WHEN 'rent' THEN 1
WHEN 'sale' THEN 2
END
)
WHERE t1.listing_type IN ('new', 'rent', 'sale');
也许你错过了这些物品
JOIN
WHERE t1.listing_type IN ('new', 'rent', 'sale')
考虑到您有默认值,您可以改用:
UPDATE 005_my_sc t1
INNER JOIN 005_my_cl t2 ON t2.pdb_id = t1.pdb_id
SET t2.listing_type = (
CASE t1.listing_type
WHEN 'new' THEN 2
WHEN 'rent' THEN 1
WHEN 'sale' THEN 2
ELSE 2
END
);