根据我们的 IP 地址列表从 DB-IP 数据库中获取位置
Get the location from the DB-IP database against our IP addlist
我们从 DB-IP.com 下载了此 IP 地址列表 location/country。
他们拥有的结构化数据如下,如您所见,它是范围内的,而不是单独的 IP。我们称之为 IPAddress_table.
IPStart; IPEnd; Country; State; City
0.0.0.0 0.255.255.255 US California Los Angeles
1.0.0.0 1.0.0.255 AU Queensland South Brisbane
1.0.1.0 1.0.3.255 CN Fujian Fuzhou
1.0.4.0 1.0.7.255 AU Victoria Melbourne
1.0.8.0 1.0.15.255 CN Guangdong Guangzhou
在我们的数据库用户(user_table)中,我们有超过 100,000 名拥有 IP 地址的用户。
如何在 MySQL 中加入这 2 个表,因为 IP 地址源是范围开始结束?
感谢您的反馈。
谢谢
尝试以下操作:
Assuming table names are IPAddress_table and user_table
Assuming Field Names are:
user_table : IPAddress (and others),
IPAddress_table: IPStart, IPEnd (and others)
SQL 尝试:
SELECT user_table.*, IPAddress_table.*
FROM user_table
INNER JOIN IPAddress_table
ON INET_ATON(user_table.IPAddress)
BETWEEN INET_ATON(IPAddress_table.IPStart)
AND INET_ATON(IPAddress_table.IPEnd)
编辑:您可能希望将其更改为 LEFT JOIN 以获取所有用户,即使 IP 范围不适合。
我们从 DB-IP.com 下载了此 IP 地址列表 location/country。
他们拥有的结构化数据如下,如您所见,它是范围内的,而不是单独的 IP。我们称之为 IPAddress_table.
IPStart; IPEnd; Country; State; City
0.0.0.0 0.255.255.255 US California Los Angeles
1.0.0.0 1.0.0.255 AU Queensland South Brisbane
1.0.1.0 1.0.3.255 CN Fujian Fuzhou
1.0.4.0 1.0.7.255 AU Victoria Melbourne
1.0.8.0 1.0.15.255 CN Guangdong Guangzhou
在我们的数据库用户(user_table)中,我们有超过 100,000 名拥有 IP 地址的用户。
如何在 MySQL 中加入这 2 个表,因为 IP 地址源是范围开始结束?
感谢您的反馈。
谢谢
尝试以下操作:
Assuming table names are IPAddress_table and user_table
Assuming Field Names are:
user_table : IPAddress (and others),
IPAddress_table: IPStart, IPEnd (and others)
SQL 尝试:
SELECT user_table.*, IPAddress_table.*
FROM user_table
INNER JOIN IPAddress_table
ON INET_ATON(user_table.IPAddress)
BETWEEN INET_ATON(IPAddress_table.IPStart)
AND INET_ATON(IPAddress_table.IPEnd)
编辑:您可能希望将其更改为 LEFT JOIN 以获取所有用户,即使 IP 范围不适合。