我有这个查询,我想计算“user”中有多少条目在“usernames”中有多个条目
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
查询有效,但速度太慢,任何想法,我可以做什么来加快这个查询?