让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Value int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(25); mysql> insert into DemoTable values(75); mysql> insert into DemoTable values(100);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
这将产生以下输出-
+-------+ | Value | +-------+ | 25 | | 75 | | 100 | +-------+ 3 rows in set (0.00 sec)
这是从表中选择等于或最接近的更大数字的查询-
mysql> select * from DemoTable -> order by abs(Value-50), Value desc -> limit 1;
+-------+ | Value | +-------+ | 75 | +-------+ 1 row in set (0.00 sec)