Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中搜索列_Sql_Mysql - Fatal编程技术网

如何在mysql中搜索列

如何在mysql中搜索列,sql,mysql,Sql,Mysql,我有两列存储值(数字),如何在两列中的值之间选择给定数字的位置 范例 `id | col1 | col2` `1 | 20 | 50` `2 | 200 | 400` `3 | 500 | 650` 如果我的值为25,如何选择值为25的记录(在本例中为第1行),您可以尝试: 如果要在搜索中包括col1和col2: select * from table where YOUR_NUM >= col1 and YOUR_NUM <= col2

我有两列存储值(数字),如何在两列中的值之间选择给定数字的位置

范例

   `id | col1 | col2`  
    `1 | 20  | 50`  
    `2 | 200 | 400`  
    `3 | 500 | 650`
如果我的值为25,如何选择值为25的记录(在本例中为第1行),您可以尝试:

如果要在搜索中包括col1和col2:

select * from table where YOUR_NUM >= col1 and YOUR_NUM <= col2;
从表中选择*,其中您的\u NUM>=col1和\u NUM col1以及\u NUM
务必使用EXPLAIN检查优化人员是否会为此使用适当的索引;理想情况下,它应该能够对col1或col2进行范围扫描
select * from table where YOUR_NUM > col1 and YOUR_NUM < col2;
select * from mytable where 25 between col1 and col2;