我正在尝试找出最简单的方法,通过用户名或用户 ID 批量查找用户的电子邮件。我是我网站的管理员,所以我拥有权限,并且我知道可以在用户个人资料中找到此信息。但是,我需要为可能数千名用户执行此操作。
情况是这样的,不幸的是,创建了数千个机器人帐户来投票我们正在进行的民意调查,我需要准确地精简最终计数以恰当地确定获胜者。我使用了民意调查结果报告数据探索器查询来返回民意调查的投票结果,但这不返回用户电子邮件。我假设可以为数据探索器插件编写另一个查询,该查询可以接受 ID 或用户名的列表并返回相应的电子邮件列表。但我对 SQL 不太了解,所以在弄清楚这一点上有点迷茫。
SELECT users.id AS user_id, user_emails.email
FROM users
LEFT JOIN user_emails ON users.id = user_emails.user_id AND user_emails.primary
WHERE users.id IN (/* 此处填写用户ID列表,例如 1,2,3 */)
-- [params]
-- int :topic_id
-- int :post_number
-- text :poll_name
SELECT polls.name AS "Poll Name",
poll_options.html AS "Answer",
poll_votes.user_id AS "User ID",
users.username AS "Username",
user_emails.email AS "Email"
FROM poll_options
INNER JOIN poll_votes ON poll_options.id = poll_votes.poll_option_id
INNER JOIN polls ON polls.id = poll_votes.poll_id
INNER JOIN users ON users.id = poll_votes.user_id
LEFT JOIN user_emails ON users.id = user_emails.user_id AND user_emails.primary
WHERE poll_options.poll_id IN (
SELECT polls.id FROM polls
WHERE polls.post_id = (
SELECT posts.id FROM posts WHERE topic_id = :topic_id AND post_number = :post_number
) AND polls.name = :poll_name
)
ORDER BY polls.name, poll_options.html
-- [params]
-- post_id :post_url
-- text :poll_name = poll
SELECT
pv.user_id,
po.html AS answer,
ue.email
FROM poll_options po
JOIN poll_votes pv ON po.id = pv.poll_option_id
JOIN polls p ON p.id = pv.poll_id
JOIN user_emails ue ON pv.user_id = ue.user_id AND ue.primary
WHERE p.post_id = :post_url
AND p.name = :poll_name
ORDER BY po.html