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