I am a big fan of http://beyondrelational.com and specially its challenges. Recent quiz (TSQL Challenge NO.49) was an interesting and very useful for DBAs and developers. Everyone must visit and try this challenge. Here is an idea to solve this. But it would be better if you try it yourself.