0
我有一个帐户和IP地址的列表,我想获取位置摘要。然而,计算对于我们的服务器来说太重了,我想知道是否有办法改变我的代码,我可以得到我所有的结果。账户数据集约为150k行和2列。转换IP地址到位置,需要优化
select city, state, count(*) from(
select account_id, 256*256*256*one+256*256*two+256*three+four as Converted, city, state from
(select *, convert(bigint, split_part(ip_address, '.', 1)) as one, convert(int, split_part(ip_address, '.', 2)) as two,
convert(int, split_part(ip_address, '.', 3)) as three, convert(int, split_part(ip_address, '.', 4)) as four from AccountsIP)
inner join
(select city, state, ip_from, ip_to from ip_ranges a left join ip_locations b on a.ip_location_id = b.ip_location_id
where country = 'US') b
on (256*256*256*one+256*256*two+256*three+four) between ip_from and ip_to
)
group by city, state