Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:31:00+00:00 2026-06-06T21:31:00+00:00

I have 2 tables as below client_table date (timestamp) ip (varchar) value1 (int) value2

  • 0

I have 2 tables as below

client_table
 date (timestamp)
 ip (varchar)
 value1 (int)
 value2 (int)

ip_address_table
 starting_ip (varchar)
 ending_ip (varchar)
 provider (varchar)

I am trying to lookup client_table entries with ip_address_table table to find the average per hour if the ip address is within the range. (if it’s not within the range ignore the row)
Below is what i have come up with

SELECT avg(value1),avg(value2)
FROM client_table
WHERE (INET_ATON(ip) BETWEEN INET_ATON(starting_ip) AND INET_ATON(ending_ip))
GROUP BY DATE(date),HOUR(date)

But, it does not give the correct output. i had a look at http://blog.jcole.us/2007/11/24/on-efficiently-geo-referencing-ips-with-maxmind-geoip-and-mysql-gis/ but struggling to write a stored function to simplify the task
any help appreciated

Thanks

EDIT: My sample data is below

client_table
"date"  "ip"    "value1"    "value2"
"2012-01-10 06:38:29"   "121.1.2.3" "1049"  "301"
"2012-01-11 06:41:35"   "58.1.2.3"  "16453" "794"
"2012-01-12 06:43:50"   "101.1.2.3" "1712"  "410"
"2012-01-13 06:44:04"   "121.1.10.3"    "6594"  "863"
"2012-01-14 06:45:00"   "79.1.2.3"  "879"   "614"

ip_address_table
"starting_ip" "ending_ip" "provider"
"121.0.0.0" "121.255.255.255" provider1
"79.1.2.0" "79.1.2.255" provider1
....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:31:02+00:00Added an answer on June 6, 2026 at 9:31 pm

    I don’t see you’re using the ip table, maybe try something like this (not tested):

    SELECT avg(value1),avg(value2)
    FROM client_table c, ip_address_table ip
    WHERE (INET_ATON(ip) BETWEEN INET_ATON(starting_ip) AND INET_ATON(ending_ip))
    GROUP BY DATE(date),HOUR(date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables described below. What I need is a single query that
i have four tables like below in sql server 2008 : TABLE 1 ->
I have a problem. I have 3 tables like below: 1) met_ID (primair) etc.
I'm using SQL Server 2008. Let's say I have two hypothetical tables like below:
I have three tables as shown in below image. Note: Lead column of projectheader
I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
I have 3 tables with values like below **tbl_product** recID pID price colour 1
I have two tables like the ones below. I need to find what exchangeRate
I have 10 tables in my database(MySQL). two of them is given below tbl_state
I have two tables names book_list and book_category . Schema is like below: book_list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.