mysql UPDATE语句,其中pricelist.import_date =(SELECT max(pricelist.import_date))

时间:2018-10-26 01:27:42

标签: mysql sql

我试图在mysql中完成更新,它仅选择最高的import_date,而我似乎无法使它正常工作。以下声明会同时更新两个价格

enter image description here

UPDATE material, pricelist
    SET price = '23'
WHERE material.id = 1936 AND
      material.id = pricelist.material_id AND
      pricelist.import_date = (SELECT max(pricelist.import_date))

1 个答案:

答案 0 :(得分:0)

这是您想要的吗?

UPDATE pricelist pl
    SET pl.price = '23'
WHERE pl.material_id = 1936
ORDER BY pl.import_date DESC
LIMIT 1;