我遇到了这个查询的问题。它返回正确的 total_names、total_events 和 total_misc,但其他三个总数(待定名称、事件和 misc)是相同的数字,并且完全是错误的数字。所有三个表都有 created_by 列。我究竟做错了什么?
SELECT
COUNT(DISTINCT names_revisions.id) AS total_names,
COUNT(DISTINCT events_revisions.id) AS total_events,
COUNT(DISTINCT misc_revisions.id) AS total_misc,
SUM(if(names_revisions.status = "Pending", 1, 0)) AS total_pending_names,
SUM(if(events_revisions.status = "Pending", 1, 0)) AS total_pending_events,
SUM(if(misc_revisions.status = "Pending", 1, 0)) AS total_pending_misc
FROM
names_revisions,
events_revisions,
misc_revisions
WHERE
:user_id IN (names_revisions.created_by, events_revisions.created_by, misc_revisions.created_by)