This is a query which updates user post counts. It takes into consideration moderated and deleted status of threads and posts, as well as each forum's "Count messages posted in this forum toward user total" setting.
UPDATE xf_user AS user SET message_count =
COALESCE(
(
SELECT COUNT(*)...