I have an IP-Location database with columns
FirstIP bigint
LastIP bigint
Country char(2)
Region varchar(128)
City varchar(128)
FirstIP is always +1 more than LastIP of the previous row. LastIP is
always -1 less than FirstIP of the next row. Here is some sample
data:
50331648 50331903 US MASSACHUSETTS BEVERLY
50331904 50332159 US NEW YORK MONROE
50332160 50332671 US CONNECTICUT FAIRFIELD
50332672 50332927 US NEW JERSEY LEBANON
For my purposes I only need FirstIP, LastIP, and Country. If I delete
the other columns (Region and City), I would then like to roll up the
remaining rows. This would greatly reduce the number of rows in the
table and would decrease my lookup times by magnitudes. The data
above would be rolled up into a single row:
50331648 50332927 US
The big question: How would I do such a roll up?
Aaron Bertrand [SQL Server MVP] - 23 Jul 2008 22:04 GMT
Assuming you know there are no overlaps across countries, you could do this:
SELECT
FirstIP = MIN(FirstIP),
LastIP = MAX(LastIP),
Country
INTO #foo
FROM original_table
GROUP BY Country;
Unless these values are arbitrary surrogates that have real data elsewhere,
I think expecting no overlaps is a pipe dream.
On 7/23/08 4:44 PM, in article
1feceda7-e693-4c4a-b2e7-5fabbc597a2d@k37g2000hsf.googlegroups.com, "Charles"
<cwindhausen@gmail.com> wrote:
> I have an IP-Location database with columns
>
[quoted text clipped - 22 lines]
>
> The big question: How would I do such a roll up?
Charles - 23 Jul 2008 22:23 GMT
I'm sorry, I put this into the wrong group. I'll move it.