Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

Roll Up IP-Location Database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Charles - 23 Jul 2008 21:44 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.