mysql-在SQL中选择UNTIL [英] mysql - SELECT UNTIL in sql

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

问题描述

我想选择行,直到找到一个确定的值并且它不是数字,所以我不能使用>或<.我怎样才能做到这一点 ?

I want to select rows until I found a certain value and it's not numeric so I cannot use > or <. How can I do this ?

示例:

-----
Value
-----
45
434
348
213
543
3445
343
123
34345

我想选择543年之前的所有记录(不按任何顺序排列)

I want to select all records before 543 (NOT ORDERED BY anything)

预先感谢

推荐答案

这个答案可能很晚,但是由于它是google上第一个带有"mysql select直到"字样的结果,希望对大家有帮助.

This answer might be late, but since it's the first result on google with term of 'mysql select until' hope this might help someone.

您可以做的是声明一个标记,如果找到了所需的值,请将标记设置为除NULL之外的任何其他值.然后,我们可以使用ISNULL来检查是否已到达该行.

What you can do is declare a marker and if you found the value needed, set the marker to any value other than NULL. Then we can use ISNULL for checking if we have reached the row.

SET @marker = NULL;
SELECT value FROM table1 WHERE ISNULL(@marker:=IF(value=543,value,@marker));

此处为演示

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

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