mySQL 选择范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10586035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:22:22  来源:igfitidea点击:

mySQL select IN range

mysql

提问by Owen

Is it possible to define a range for the IN part of the query, something like this

是否可以为查询的 IN 部分定义一个范围,像这样

SELECT job FROM mytable WHERE id IN (10..15);

Instead of

代替

SELECT job FROM mytable WHERE id IN (10,11,12,13,14,15);

回答by ESG

You can't, but you can use BETWEEN

你不能,但你可以使用 BETWEEN

SELECT job FROM mytable WHERE id BETWEEN 10 AND 15

Note that BETWEENis inclusive, and will include items with both id 10 and 15.

请注意,这BETWEEN是包容性的,将包括 ID 为 10 和 15 的项目。

If you do not want inclusion, you'll have to fall back to using the >and <operators.

如果您不想包含,则必须退回使用>and<运算符。

SELECT job FROM mytable WHERE id > 10 AND id < 15

回答by Lalit Dashora

To select data in numerical range you can use BETWEENwhich is inclusive.

要选择数字范围内的数据,您可以使用BETWEENwhich is inclusive。

SELECT JOB FROM MYTABLE WHERE ID BETWEEN 10 AND 15;