3

数ヶ月前、私はこれに似た何かについて質問し、助けを受けて、答えがあると思いました。3か月後、これが100%機能しなかったので、もう少し助けが必要ですが、理解が深まったので、質問をもっとよくすることができます。

私はmysqlテーブルを持っていますid, userid, rounds, reps, exerciseid

自分が引っ張っているエクササイズに固有の最高のラウンドをユーザーに引っ張る必要があります。したがって、exerciseid8の場合、そのためにユーザーがトップラウンドである必要がありますexerciseidが、ユーザーが同じroundsものを複数回持っている場合、これは頻繁に発生しrepsます。真の最高のパフォーマンスを得るには、それをで並べ替える必要があります。次に、これらの結果を取得した後、このデータセットをroundsで並べ替える必要があります。repsしたがって、複数の一意のユーザーが同じroundsものを持っている場合は、で並べ替えられrepsます。

これは純粋なmysqlで実行できますか、それともデータをプルしてすべてをPHPで並べ替えたほうがいいですか?

SELECT
  max(l.rounds) as rounds,
  l.reps,l.userid
from leaderboard l
where l.exerciseid = 8 
group by l.userid 
order by 
  rounds desc,
  reps desc 

構造の例最初にこれはsmapleセットです

userid  exerciseid  rounds  reps
--     --     --
1    8  23  10
1    8  23  15
1    8  20  10
2    8  28  19
2    8  15  12
3    8  40  29


results I want

userid  exerciseid  rounds  reps
--     --     --
3    8  40  29
2    8  28  19
1    8  23  15
4

2 に答える 2

0

どうですか:

SELECT
  max(l.rounds) as rounds,
  max(l.reps) as reps,l.userid
from leaderboard l
where l.exerciseid = 8 
group by l.userid, l.exerciseid 
order by 
  rounds desc,
  reps desc 
于 2012-12-28T20:02:57.183 に答える
0

私がこれを正しく理解していれば、最初にユーザー ID とラウンドでグループ化して、ラウンドの maxreps を取得する必要があります。次に、これから最大ラウンドを選択します。

これを MySQL で表現する 1 つの方法を次に示します。

select userid, rounds, maxreps
from (SELECT userid, l.rounds, MAX(l.reps) as maxreps
      from leaderboard l
      where l.exerciseid = 8 
      group by l.userid, l.rounds
     ) ur
where exists (select 1 from leaderboard lb where ur.userid = lb.userid and lb.exerciseid = 8 group by lb.userid having max(rounds) = ur.rounds))
order by rounds desc, maxreps desc 
于 2012-12-28T19:51:21.450 に答える