Sunday, August 31, 2008

In the last weeks I found myself completely immersed in a new site in a way that didn’t happen to me in a very long time. And the site is about… development, computer languages, bugs, hints, programming. Wow.

This site is – I am one of the very lucky beta tester, and I cannot be happier: the site is interesting, addicting, you learn a lot of things and you can ask for help to an audience of experts.

The thing comes from a couple of very interesting guys: Jeff Atwood and Joel Spolsky. This is in itself a guarantee of high-level content, and it’s true. If you’re curious, go here and browse a little, and listen to the podcasts.

In just few days I solved a couple of problems of mine, but the very interesting thing is what I learned, and what I decided to study, because of some answers I read, that stimulated my own curiosity. Down below you can have a look to the very last answers posted since 10 minutes ago.

A boost. A site in which you can learn and share your learning with other people. A place to go when google search didn’t bring you to the solution.

A place in which I’m wasting a huge lot of time… :-)


Friday, August 15, 2008

Top 50 – SQL

Some time ago I had to select the users from a table that reached the first 50 scores in a particular game. Not 50 users, but the users that made the first top 50 scores. Here’s my solution, for my future memory :-)

DECLARE @minscore int
    (userid INT PRIMARY KEY,
     score int)

INSERT INTO #top50 (userid, score)
    SELECT top 50 userid, TotalScore 
    FROM UserList 
    order by TotalScore desc

select @minscore = min(score) from #top50

delete from #top50 where score = @minscore

INSERT INTO #top50 (userid, score)
    SELECT userid, TotalScore 
    FROM UserList where TotalScore = @minscore

select * from UserList 
    where userid in (select userid from #top50)
    order by TotalScore desc

Hope this helps


EDIT: what about a simple one like

select userid, TotalScore
from UserList
where TotalScore in
(select distinct top 50 TotalScore from UserList order by TotalScore desc)

uff... :-)