我有一个查询,想要计算“用户”中有多个“用户名”条目的数量。
SELECT usernames.NAME,
COUNT(user.id)
FROM user
INNER JOIN user_username ON user.id = user_username.user_id
INNER JOIN usernames ON user_username.user_username_id = usernames.id
WHERE
user.datecreated BETWEEN '2016-01-01' AND '2016-09-01'
AND user.id IN
(
SELECT user_id
FROM user_username
GROUP BY user_id
HAVING COUNT(*) > 1
)
GROUP BY usernames.NAME
ORDER BY user.id DESC
这个查询可以正常工作,但速度太慢了,你有什么想法可以加快这个查询的速度吗?