Hi, I tried this and it seems to work:
SELECT SUBSTRING_INDEX(INET_NTOA(ip), '.',3) AS addr, COUNT(*) AS addrsum FROM
ips GROUP BY addr;
Perhaps you don't have your IP adresses stored as integers but instead as
text. Then the following query is for you!
SELECT ip, COUNT(*) from tbl_MasterIp group by ip;
Would then be something like this:
SELECT SUBSTRING_INDEX(ip, '.', 3) AS ip, COUNT(*) AS addrsum FROM
tbl_MasterIp Group By ip;
On Monday 08 December 2003 15.23, chad kellerman wrote:
> Hello everyone,
> I have a mysql table tha holds a variety of ip address. I am trying
> to work out a select statement that will give me a count(*) grouped by
> the first 2 octets of the ip.
> if the ip table contains:
> how can my:
> SELECT ip, COUNT(*) from tbl_MasterIp group by ip;
> be changed so that I get back
> ip COUNT(*)
> 10.102.1 20
> 192.168.123 30
> 192.168.0 10
> or whatever the ip counts should be. I have about 5 different octets
> within this table.
> I am using mysql 3.*
> Thanks for any help...