SQL Server Group By which counts occurrences of a score -
This can be a bit difficult to explain, but there are two columns in my SQL Server database that I have simplified ...
Item
ID
itemName
Vote count score
Vote
itemID < Basically I am accumulating every vote placed on a table, but can also calculate the number of votes for each item in the item table (outside average 10)) (which I know is that day Security is a duplicate, but it tends to make things easier.)
However, I would like to create a SQL query that finds 2 items with the lowest score. It will be as easy as you think you want to do this ...
Select items based on order items from ASC;
However, the customer has added the following complexity.
When 2 or more items have the same number, then the maximum number of votes will be given above if 2 or more items have the same digits and the same number is 10/10 votes, Then this item will rank above another 9 to 10 votes and so on, below the number of 0/10 votes, if everything else is the same.
In this way, the challenge is that if all these criteria are to be ranked by these criteria then take 2 below. I have tried to make groups, collect and combine all the "sub-queries".
Explanation
Average score for any item is deposited in the item table and votes are cast in the votes table against each vote. Initially, we need to rank on the basis of the average score (ISCOR) and where there is only one score of 2 items, we have to start calculating the number of 10/10 in the votes associated with that item (v.score) .
Therefore, we can have an object called "T-shirt" whose average score is 5/10 This low score comes from 6 votes with 5,5,5,5,5,5 .
The next item is called "Ferrari" and its average score is 5/10, but this item is only 4 votes with the following score 6,5,5,4
select top 2 i.itemName item I have left externally (choose item idid In the case of score 10, zodiac (score when score = 9, then 1 point) score as score (score = 10 then 1 end) as the score (score 8 = score score as 8, then 1 end) Score score (score when case = 7 then 1 end) score 7, score (case when score = 6 then 1 end) as score 6, score (case when score = 5 then 1 end) score 5 In the form, the zodiac (case when score = 4 then 1 end) score 4, sum (in case score = 3 then 1 end) La score 2 = 1 then 1 end) As the score 2, the zodiac sign (case when score = 1 then 1 end) by item 1 by the item ID id). On id = v I.score, v.score10, v.Score9, v.Score8, v.Score7, v.Score6, v.Score5, v.Score4, v.Score3, v.Score2, v.Score1
by the IICIR order.
Comments
Post a Comment