MySQL Query for Average of last 2 attempts

后端 未结 5 1477
悲&欢浪女
悲&欢浪女 2021-01-23 07:27

I have a table:

quiz userid  attempt grade

1      3        1     33

2      3        1     67

1      3        2     90

10     3        4     20

2      3              


        
5条回答
  •  一个人的身影
    2021-01-23 08:23

    Selecting the last two rows = selecting the first two rows of a reversed set.

    Simply order by attempt DESC (that makes it 4,3,2,1) and then grab the first two (4,3).

    SELECT * FROM table WHERE <...> ORDER BY attempt DESC LIMIT 2

提交回复
热议问题