选择上一行mysql? [英] Select previous row mysql?

查看:76
本文介绍了选择上一行mysql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个具有主要ID的mysql表和另一个名为gameScore的字段,我可以按照...做些什么...

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 = 100 ORDER BY gameScore ASC

这将获得ID为100的gameScore,但是我想做的是让mysql按gameScore排序表,然后选择ID = 100的上一行,如果可以的话,谢谢...

This will get the gameScore for the id 100, but what I would like to do is have mysql order the table by gameScore and then select the previous row to where the id = 100, if that makes sense thanks...

推荐答案

类似的东西-

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

要查找先前的记录,我们需要选择确切的当前记录,例如,它是id = 100且gameScore = 50的记录.

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

这篇关于选择上一行mysql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆