我是否可以根据每行的选择运行更新查询?这就是我在想的尝试:
UPDATE adverts SET advert_visits = (SELECT COUNT(earning_id) FROM earnings WHERE earning_advert_id = 1093)
但是我不确定如何让select从广告表中为每一行应用正确的advert_id?
或许这只是一种完全无效的语法,我不确定。
答案 0 :(得分:1)
只需参考更新的表格:
UPDATE adverts
SET advert_visits = (
SELECT COUNT(earning_id)
FROM earnings
WHERE earning_advert_id = adverts.advert_id
)