How to create a GROUP BY for use with ip address range?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shyckymn
    New Member
    • Mar 2007
    • 5

    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

    Range 172.17.17: 3 machines
    Range 172.18.196: 2 machines
    Range 172.22.3: 1 machine
  • poddus
    New Member
    • Mar 2007
    • 2

    #2
    Originally posted by Shyckymn
    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

    Range 172.17.17: 3 machines
    Range 172.18.196: 2 machines
    Range 172.22.3: 1 machine
    You can (in ver.8) group by
    SUBSTR(ip_addr, 1,
    LOCATE('.',ip_a ddr,
    LOCATE('.',ip_a ddr,LOCATE('.', ip_addr)+1)+1)-1)
    because
    SELECT SUBSTR('172.18. 196.12',1,
    LOCATE('.','172 .18.196.12',
    LOCATE('.','172 .18.196.12',LOC ATE('.','172.18 .196.12')+1)+1)-1)
    FROM SYSIBM.SYSDUMMY 1
    is 172.18.196

    regards,
    poddus

    Comment

    • poddus
      New Member
      • Mar 2007
      • 2

      #3
      you can (in ver.8) group by
      SUBSTR(ip_addr, 1,
      LOCATE('.',ip_a ddr,
      LOCATE('.',ip_a ddr,LOCATE('.', ip_addr)+1)+1)-1)
      becase FROM SYSIBM.SYSDUMMY 1
      SELECT SUBSTR('172.18. 196.12',1,
      LOCATE('.','172 .18.196.12',
      LOCATE('.','172 .18.196.12',LOC ATE('.','172.18 .196.12')+1)+1)-1)
      from sysibm.sysdummy 1 is 172.18.196
      regards,
      poddus

      Comment

      • Shyckymn
        New Member
        • Mar 2007
        • 5

        #4
        Ok, thanks a lot!

        Comment

        Working...