Need query to parse mysql table URL column for distinct ip and output grouped results.

Hello,

Please help me to construct the mysql query that will find all distinct ips from the URLs column and will group the results by these ips.

url column entry examples:

http://10.10.0.69/gate/profile.aspx?mop6LFfL0XU0MPpggZSBcSkazbVvGYNHBJsMsxb9X1Rn8m7+JB5hNiTKPIEJVdzDqK
http://192.168.11.7/sUtils/GetListing.aspx?Session_Info=CCeT/AvRx48puN1a8BbNekz72ToJW4KFnrIGwn1Mg9Injyw6V3

desired output:
Ip| count

TIA.
Joe.
TegRNDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
based purely on the sample of data shown:
select
`ip`, count(*) as frequency
from (
      select
          REPLACE( SUBSTRING_INDEX(`URL`,'/',3) , 'http://','') as `ip`
      from table1
      where left(`URL`,7) = 'http://'
    ) as g
group by `ip`

Open in new window


details:
    CREATE TABLE Table1
        (`URL` varchar(500))
    ;
        
    INSERT INTO Table1
        (`URL`)
    VALUES
        ('http://10.10.0.69/gate/profile.aspx?mop6LFfL0XU0MPpggZSBcSkazbVvGYNHBJsMsxb9X1Rn8m7+JB5hNiTKPIEJVdzDqK'),
        ('http://192.168.11.7/sUtils/GetListing.aspx?Session_Info=CCeT/AvRx48puN1a8BbNekz72ToJW4KFnrIGwn1Mg9Injyw6V3')
    ;
    
**Query 1**:

    select
    `ip`, count(*) as frequency
    from (
          select
              REPLACE( SUBSTRING_INDEX(`URL`,'/',3) , 'http://','') as `ip`
          from table1
          where left(`URL`,7) = 'http://'
        ) as g
    group by `ip`

**[Results][2]**:
    |           ip | frequency |
    |--------------|-----------|
    |   10.10.0.69 |         1 |
    | 192.168.11.7 |         1 |

  [1]: http://sqlfiddle.com/#!9/d5796/4
  [2]: http://sqlfiddle.com/#!9/d5796/4/0

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TegRNDAuthor Commented:
Works as expected, thank you!
PortletPaulEE Topic AdvisorCommented:
It was a pleasure. Cheers, Paul
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.