Mysql Query for Rank (RowNumber) and Groupings -
I have a similar problem
but it is in SQL Server and MySQL "partition support Does not "As I know what can I do now? Here's the question:
I have a table with some columns: User, Category, Value
and I want to do a query which will give me ranking, According to, but reset to the category.
Example:
user1 class A10 user 2 category A11 user 3 category A9 user 4 category B3 user 1 category B11query must return:
rank user category 1 user 2 category a2 user 1 category 3 user 3 category 1 user 1 category b2 user4 category b< / Pre>Any ideas?
edit 2 : based on OP's comment:
This works only with some incorrect ranking and it is in the first
rank. When the toprankin the samecategoriessimilarvalueis one of the first inrankand the second is in 2bt They have the followingrank(1)
the following changes have been suggested:
Selection of Rank Please, user, category, price (user select, @cc: = category category, @ cv: = value value, case @ pc = @ cc and @ pv = @ cv, then @rn: = @ rn when @ PC = @cc and @pv! = @vv then @rn: = (@ rn + 1) and ray As a @ rn: = 1 end, @pc: @ccc as temp_currCat, @pv: = @ cv as temp_currVal user_category_values, (select @pc: = '', @cc: = ' ', @pv: =' ', @cv: =' ', @rn: = 0) in order of row_nums category, according to the value) result; Demo @
Comments
Post a Comment