Tsvetilin Boynovski Tsvetilin Boynovski - 1 year ago 63
MySQL Question

PHP query to DB

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

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:

  1. IP - Visits - 542

  2. IP - Visits-451

  3. IP - Visits-331

I hope you understand me correctly.

Answer Source

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