I have a table where I store information about every single time a page has been loaded. So I have these rows: id, ip, date. Now I want to SELECT the 5 most active IP addresses and get the total number of times they have loaded a page. So the result I get should look like this:
- IP - 193.211.187.1 Visits - 542
IP - 192.122.152.1 Visits-451
IP - 191.141.100.1 Visits-331
I hope you understand me correctly.
asked Jun 23, 2016 at 14:55
Tsvetilin Boynovski
6461 gold badge5 silver badges10 bronze badges
-
1counting rowspostrel– postrel2016年06月23日 14:57:33 +00:00Commented Jun 23, 2016 at 14:57
2 Answers 2
You should be able to use group by and count to pull the most views by IP.
select ip, count(*) as count
from logs
group by ip
order by count desc
limit 5
Simple Demo: http://sqlfiddle.com/#!9/fa26a3/1
answered Jun 23, 2016 at 15:03
chris85
23.9k7 gold badges37 silver badges51 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Tsvetilin Boynovski
Very adequate answer. Thanks :)
use this query change table name according to yours
SELECT ip, count( ip) visits
FROM table
GROUP BY ip
ORDER BY visits DESC
LIMIT 5
answered Jun 23, 2016 at 15:10
Passionate Coder
7,3042 gold badges24 silver badges50 bronze badges
Comments
default