让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(100,200); mysql> insert into DemoTable values(200,100); mysql> insert into DemoTable values(300,400); mysql> insert into DemoTable values(400,300); mysql> insert into DemoTable values(500,600); mysql> insert into DemoTable values(600,500);
使用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)