如果表是set_price,则尝试更新表并将列设置为来自另一个表的值。
两个记录共享相同的prod_id。有人能看看我的问题并告诉我它有什么问题吗?
update list_items l
set purchased = "YES",
set_price = IFNULL(set_price,(select pricelast
from inventory i where i.prod_id=l.prod_id))
where l.list_id=1发布于 2015-04-08 19:06:43
一种更好的方法是在使用case时使用联接更新--当
update list_items l
left join inventory i on i.prod_id=l.prod_id
set l.purchased = 'YES',
l.set_price =
case
when l.set_price is null then i.pricelast else l.set_price
endhttps://stackoverflow.com/questions/29523113
复制相似问题