|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-07-23 : 08:56:52
|
| Salim writes "I'm trying to compose a single SQL statement that will take an unorderd list of items in a category and sort them according to their category and rank within a category... the catch is, I dont much care about what score an item got, just it's position in the rank.Type, Name, ScoreApple, Cox's, 4Citrus, Satsuma, 7Citrus, Grapefruit, 4Apple, Braburn, 5Apple, GSmith, 8Citrus, Lemon, 1Citrus, Lime, 0Citrus, Tangerine, 9Apple, Cooking, 2Misc, Pineapple, 5The result of the query should look like this:Type, Name, RankApple, GSmith, 0Apple, Braburn, 1Apple, Cox's, 2Apple, Cooking, 3Citrus, Tangerine, 0Citrus, Satsuma, 1Citrus, Grapefruit, 2Citrus, Lemon, 3Citrus, Lime, 4Misc, Pineapple, 0The list has been sorted by 'type' and then by 'Score' descending.The 'Rank' column can be computed as the numer of items in the same category with a higher score than the current item.To make matters harder, this must be implemented as a single SELECT statement - sub-selects and set-operators are allowed.Sal" |
|