我有2個表如下的MySQL查詢的IP地址範圍
client_table
date (timestamp)
ip (varchar)
value1 (int)
value2 (int)
ip_address_table
starting_ip (varchar)
ending_ip (varchar)
provider (varchar)
我試圖查找與ip_address_table表client_table條目以平均每小時如果IP地址在此範圍內。 (如果它不在該範圍內忽略該行) 下面是我想出了
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)
但是,它並沒有給出正確的輸出。我看了一眼http://blog.jcole.us/2007/11/24/on-efficiently-geo-referencing-ips-with-maxmind-geoip-and-mysql-gis/而是奮力編寫一個存儲功能,以簡化任務 任何幫助讚賞
感謝
編輯:我的樣本數據低於
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
....
我選擇不使用這種方法,因爲性能非常差。感謝所有的幫助 – Linus