简体   繁体   中英

MySql find multiple rows with same value in a column

I record IP addresses in my DB and i want to look at accounts that have the same IP address as eachother. I'd like to show only results with more then one IP addresses. I preferentially would like it sorted by IP addressed used the most (IE if i have 30accounts with 127.0.0.1 as my ip i rather have that higher then 10ip address that belong to 192.168.1.123).

How do i write this query? I am using mysql

SELECT ip, COUNT(*)
FROM Table    
GROUP BY ip    
HAVING COUNT(*) > 1    
ORDER BY COUNT(*);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM