根据 MySQL 中的比较显示两列中的记录?
首先,我们创建一个表 −
mysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> ); Query OK, 0 rows affected (0.54 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(100,200); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(200,100); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(300,400); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(400,300); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(500,600); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(600,500); Query OK, 1 row affected (0.18 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
这将产生以下输出 −
+------+------+ | Num1 | Num2 | +------+------+ | 100 | 200 | | 200 | 100 | | 300 | 400 | | 400 | 300 | | 500 | 600 | | 600 | 500 | +------+------+ 6 rows in set (0.00 sec)
以下是对比两列中值的查询 −
mysql> select *from DemoTable where Num1 < Num2;
输出
这将产生以下输出 −
+------+------+ | Num1 | Num2 | +------+------+ | 100 | 200 | | 300 | 400 | | 500 | 600 | +------+------+ 3 rows in set (0.00 sec)
广告