我正在做一个从某人的定制CMS到WP安装的特殊迁移。我成功地将帖子和评论迁移到各自的表中。现在,我需要将每个匹配id的评论计数放入wp\\u posts表中。我很接近,我想:
SELECT COUNT(comment_content) AS total_comments, comment_post_ID AS commentID
FROM wp_comments
GROUP BY comment_post_ID;
--mysql won\'t let me run the group by on just the returned count column, so I\'m stuck with two columns of data when I just want to insert one
UPDATE wp_posts SET comment_count = total_comments WHERE wp_posts.ID = commentID;
--So I tried to set my returned data to variables and assign them into the update statement..which doesn\'t work
无论如何,也许我需要迭代所有帖子,找到一个匹配的ID,然后通过移动光标来更新它?还是有更简单的方法让我错过了?