Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Puzzle 14: Puzzle Lite #2 on 'roids 5

Status
Not open for further replies.

vongrunt

Programmer
Joined
Mar 8, 2004
Messages
4,863
Location
HR
Take data from SQL Puzzle Lite #2 (see thread183-1197121).

Make result set containing 48 rows and three columns: N (tinyint), State and Capital

1st row (N=2): state/capital closest to two other capitals
2nd row (N=3): state/capital closest to three other capitals
...
repeat until N=49

Criteria "closest" is based on sum of distances. For N=2 example, every city has two nearest cities - but (only) one has minimal sum of distances to nearest two cities and that is... Boston, I think.

Include sum in result set if you want.

Best exec time (measured w/ profiler) wins it all.

Plz no cheating - especially about Hawaii :P

------
Theory: everybody knows everything, nothing works
Practice: everything works, nobody knows why

[banghead]
 
Actually primary key on (Capital, distance) should be faster...

Of course that will crash if one capital city has two same distances (very unlikely but...).

------
Theory: everybody knows everything, nothing works
Practice: everything works, nobody knows why

[banghead]
 
right you are vongrunt. With that mod to chrissie's code, I get...

Vongrunt: 0.17 seconds
gmmastros: 0.30 seconds
chrisse1: 2.8 seconds

Without the mod, chrissie's code is running at 48 seconds.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
OK, chri<.ss<.ie got a sta<.r :P

I'll eventually post some "clean" queries (SQL2005 included) with explanations later.

Next puzzle is yours.

------
Theory: everybody knows everything, nothing works
Practice: everything works, nobody knows why

[banghead]
 
Yeepie.

I tried your suggestion george and yes it improved a lot down to 13 secs.

Then I changed them back to temp tables and it stayed at 13 secs

Christiaan Baes
Belgium

"My new site" - Me
 
Star to vongrunt for fastest execution.
Star to chrissie for learning the most. [wink]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top