WHERE
句を追加するとき、
UPDATE authors SET total_articles =
(
SELECT COUNT(*) FROM articles
WHERE articles.author_id=authors.author_id
GROUP BY author_id
)
しかし著者が出版された論文を更新するため、このクエリを使用
UPDATE authors SET published_articles =
(
SELECT COUNT(*) FROM articles
WHERE articles.author_id=authors.author_id AND articles.status='published'
GROUP BY author_id
)
count(*)
は、公開された記事の数を正しくカウントしません。あなたのようなクエリを変更した場合
UPDATE authors SET published_articles =
(
SELECT COUNT(*) FROM articles a
JOIN authors au ON a.author_id = au.author_id
WHERE a.status='published'
GROUP BY a.author_id
)