I'm using the SELECT below to pull a list of parts and rank them by the number of times that they have been ordered. I would like to take them and then convert the 'Ranking' in high level text categories:Top 20% Show Actual Ranking2nd 20% Display Ranking as 'High'3rd 20% Display Ranking as 'Medium'4th 20% Display Ranking as 'Low'5th 20% Display Ranking as 'Very Low'Thus the results might appear asRow_Number() Ranking Part1 1 Jim Bean2 2 Maker's Mark3 3 Jack Daniels4 High iPhone 65 High iPhone 6s6 High iPhone 57 Medium Dell Latitude 64308 Medium ID Tag9 Medium Class Ring10 Low Rock11 Low Cigar Cutter12 Low Cigar13 Very Low Torch14 Very Low Tape Measure15 Very Low USB Cable(And yes, I just described the objects on my desk.)[code="sql"]SELECT *, ROW_NUMBER() OVER (ORDER BY Total_Orders Desc) RankingFROM(SELECT dbo.Parts.NameLong Order_Item, (SELECT COUNT(PartId) AS Expr1 FROM dbo.Orders WHERE (PartId = dbo.Parts.Id)) AS Total_OrdersFROM dbo.Parts) s1[/code]
↧
Convert Value Returned by Row_Number() Function to Text Based on Relationship to Overall Result Set
↧