Mysql Range 动态带值

我有一张表,其中存储了我的级别以及升级到另一个级别所需的积分,如下所示:


id | level | pointsrequired

-----------------------------

1  | 0     | 0

2  | 1     | 20

3  | 2     | 50

4  | 3     | 90

现在需要的这个点可以是动态的,所以不确定我是否使用修复案例值,我想检查我的当前点是否大于前一个并且小于下一个我的级别应该升级,否则它很好。


这是我来的查询,但不确定这是不是正确的解决方案。


SELECT * FROM tbl WHERE pointsrequired BETWEEN 25 AND  (SELECT MAX(pointsrequired) FROM tbl) LIMIT 1

就像以前我的积分是 0,现在我得到 25,我应该升级到 2 级任何其他对此不确定的解决方案。


慕斯王
浏览 66回答 3
3回答

qq_遁去的一_1

SELECT `level` FROM tbl WHERE pointsrequired > 25 ORDER BY pointsrequired LIMIT 1

守着一只汪

那么25岁你想获得2级吗?SELECT&nbsp; &nbsp; &nbsp; `id`&nbsp; &nbsp; , `level`&nbsp; &nbsp; , `pointsrequired`FROM&nbsp; &nbsp; tblWHERE&nbsp; &nbsp; pointsrequired <= 25ORDER BY&nbsp; &nbsp; pointsrequired DESCLIMIT 1

慕桂英4014372

我认为这是您想要的逻辑:SELECT *FROM tbl t1WHERE&nbsp; &nbsp; pointsrequired BETWEEN 25 AND&nbsp; &nbsp; &nbsp; &nbsp; (SELECT t2.pointsrequired FROM tbl t2 WHERE t2.pointsrequired > 25&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ORDER BY t2.pointsrequired LIMIT 1);子查询查找高于输入值 25 的下一个直接级别。
打开App,查看更多内容
随时随地看视频慕课网APP