在 MySQL 中,在两个列值之间选择一个特定值?
mysqlmysqli database更新于 2025/11/14 22:04:17
首先我们创建一个表 −
mysql> create table DemoTable787 ( Score1 int, Score2 int, Name varchar(100) ); Query OK, 0 rows affected (0.84 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable787 values(34,56,'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable787 values(73,86,'Robert'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable787 values(90,99,'David'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable787 values(80,89,'Adam'); Query OK, 1 row affected (0.21 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable787;
这将产生以下输出 -
+--------+--------+--------+ | Score1 | Score2 | Name | +--------+--------+--------+ | 34 | 56 | Chris | | 73 | 86 | Robert | | 90 | 99 | David | | 80 | 89 | Adam | +--------+--------+--------+ 4 rows in set (0.00 sec)
以下是在两列值之间选择特定值的查询 −
mysql> select Name from DemoTable787 where 56 between Score1 and Score2;
这将产生以下输出 -
+-------+ | Name | +-------+ | Chris | +-------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

