sql - MySQL ranking query is not giving expected value -




i have following situation: there table relates wallets , divisions. have rank users in same division. sql code using working, when try put row numbers gives strange results. tried lot of different strategies nothing worked me.

select * , @currow := @currow + 1 row_number  division_user,  wallet join   (select @currow := 0) r division_user.division_id in (select division_user.division_id                                      division_user                                      division_user.wallet_id in                                               (select wallet.id wallet wallet.user_id = 1 )) ,  division_user.wallet_id = wallet.id  group wallet.id  order wallet.weekly_profit_value desc 

the output of query is:

   1,3    2,5    3,1 

desired result

    1,1     2,2     3,3 

variables , group by don't work together. also, never use commas in from clause. always use proper, explicit join syntax.

select duw.*, (@currow := @currow + 1) row_number (select du.*, w.*       division_user du join             wallet w             on du.wallet_id = w.id       du.division_id in (select du2.division_id                                 division_user du2                                du2.wallet_id in (select w2.id                                                        wallet w2                                                        w2.user_id = 1                                                       )                               )       group w.id      ) duw cross join     (select @currow := 0) params order w.weekly_profit_value desc 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -