如何从以下查询中排除user_id为1的用户?
这是我的MySQL代码。
"SELECT users.*, COUNT(*) as coun, users_comments.user_id
FROM users_comments
INNER JOIN users ON users_comments.user_id = users.user_id
GROUP BY users_comments.user_id
ORDER BY coun DESC
LIMIT 5"
答案 0 :(得分:3)
SELECT users.*, COUNT(*) as coun, users_comments.user_id
FROM users_comments
INNER JOIN users ON users_comments.user_id = users.user_id
WHERE users.user_id != 1 <---------------
GROUP BY users_comments.user_id
ORDER BY coun DESC
LIMIT 5
答案 1 :(得分:0)
SELECT users.*, COUNT(*) as coun, users_comments.user_id
FROM users_comments
JOIN users ON users_comments.user_id = users.user_id
WHERE users.user_id not in(1,3)
GROUP BY users_comments.user_id
ORDER BY coun DESC
LIMIT 0,5