我有user_id
和ip
我需要拥有多个user_id
示例表
|user_id| |ip|
1, 127.0.0.1
2, 127.0.0.1
3, 82.12.12.12
3, 82.12.12.12
3, 92.15.15.15
所以我的结果必须是127.0.0.1
以下查询为我提供了多次使用的所有IP
SELECT ip, COUNT(user_id)
FROM user_login_histories
GROUP BY ip HAVING COUNT(DISTINCT(user_id)) > 1
ORDER BY ip
我缺少什么
答案 0 :(得分:1)
试试这个:
SELECT ip, GROUP_CONCAT(DISTINCT user_id)
FROM user_login_histories
GROUP BY ip
HAVING COUNT(DISTINCT user_id) > 1
ORDER BY COUNT(DISTINCT user_id) DESC
答案 1 :(得分:1)
试试这个:
SELECT ip, COUNT(DISTINCT(user_id))
FROM user_login_histories
GROUP BY ip
HAVING COUNT(DISTINCT(user_id)) > 1
ORDER BY COUNT(DISTINCT(user_id))