| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

03-14-07, 07:31
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 11
|
|
How to create a GROUP BY for use with ip address range?
|
|
Dudes,
How can I make a GROUP BY function into an SQL instruction, to count how much machines by ip address range (until the 3rd range)?
Ex: (Existent registers for a field called ip_addr)
172.17.17.1
172.17.17.2
172.17.17.3
172.18.196.12
172.18.196.22
172.22.3.1
Must returns:
Network 172.17.17: 3 machines
Network 172.18.196: 2 machines
Network 172.22.3: 1 machine
|
|

03-14-07, 07:49
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 11
|
|
How to create a GROUP BY for use with ip address range?
Dudes,
How can I make a GROUP BY function into an SQL instruction, to count how much machines by ip address range (until the 3rd range)?
Ex: (Existent registers for a field called ip_addr)
172.17.17.1
172.17.17.2
172.17.17.3
172.18.196.12
172.18.196.22
172.22.3.1
Must returns:
Network 172.17.17: 3 machines
Network 172.18.196: 2 machines
Network 172.22.3: 1 machine
|
|

03-14-07, 07:59
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
|
|
You write a UDF that takes the whole IP address column and returns just the first 3 ranges. Then you query looks like: SELECT MyUDF(IPCOL),count(*) from MYTable group by MyUDF(IPCOL) ORDER BY 1
HTH
Andy
|
|

03-14-07, 08:00
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Answered in duplicate thread.
|
|

03-14-07, 08:30
|
|
Registered User
|
|
Join Date: Jul 2006
Location: Pune , India
Posts: 433
|
|
locate 3 location of '.'
select loc,count(*) from (select (substr(IP,1,locate('.',IP,(locate('.',IP,((locate ('.',IP))+1))+1)))) As loc from Test11 )As B
group by loc
LOC 2
--------------- -----------
172.17.17. 3
172.17.172. 1
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
|
|

03-15-07, 04:21
|
|
Registered User
|
|
Join Date: May 2006
Posts: 82
|
|
I couldn't test this query. Would this work for you..?
SELECT SUBSTR(LOC,1,LOCATE('.',LOC,3)),COUNT(*) from tablename GROUP BY SUBSTR(LOC,1,LOCATE('.',LOC,3))
__________________
Vinay,
|
|

03-15-07, 08:23
|
|
Registered User
|
|
Join Date: Jul 2006
Location: Pune , India
Posts: 433
|
|
3 parameter in locate specifies the starting position from where to start search
values locate('r','rahulrrsingh',2)
1
-----------
6
values locate('r','rahulrrsingh',3)
1
-----------
6
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
|
|

03-15-07, 15:59
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 11
|
|
"vini_srcna", sorry, but it doesn't work...
Result:
0.0. 2
0.1. 1
1.1. 3
10. 500
169. 11
172. 4312
192. 195
200. 16
|
|

03-15-07, 16:02
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 11
|
|
"rahul_s80", your tip was simply perfect!
Thanks a lot, dude!
|
|

03-16-07, 03:47
|
|
Registered User
|
|
Join Date: May 2006
Posts: 82
|
|
Thats great. Thanks for the update.
__________________
Vinay,
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|