我有两个这样的结构表:
content (content_id, content_type, user_id, time, comment_count)
comments (comment_id, content_id, userid, comment, comment_time)
我想要做的是用评论总和更新comments_count字段,即评论表中的COUNT(content_id)。
我无法弄清楚正确的语法
答案 0 :(得分:2)
UPDATE content c1 SET comment_count=(
SELECT COUNT(c2.content_id) FROM comments c2
WHERE c1.content_id = c2.content_id
)
答案 1 :(得分:0)
Cross Table Update with MySQLCross Table Update with MySQL
UPDATE product p, productPrice pp
SET pp.price = pp.price * 0.8
WHERE p.productId = pp.productId
AND p.dateCreated < '2004-01-01'