Select previous row mysql?

后端 未结 5 1319
猫巷女王i
猫巷女王i 2021-01-27 10:11

If I have a mysql table which had primary ids and another field called gameScore can I do something along the lines of...

SELECT gameScore FROM table1 WHERE id =         


        
5条回答
  •  长发绾君心
    2021-01-27 10:25

    Something like this -

    SELECT t1.* FROM table1 t1
      JOIN (
        SELECT id, MAX(gameScore) gameScore FROM table1
          WHERE id = 100 AND gameScore < 50 ORDER BY gameScore
      ) t2
        On t1.id = t2.id AND t1.gameScore = t2.gameScore
    

    To find previous record we need to select exact current record, in example it is a record with id = 100 and gameScore = 50.

提交回复
热议问题