为了比较两个数字字符串,让我们首先创建一个表。以下是查询-mysql> create table compareTwoStringsDemo
-> (
-> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> Value varchar(100)
-> );
以下是使用insert命令在表中插入一些记录的查询-mysql> insert into compareTwoStringsDemo(Value) values('1235667');
mysql> insert into compareTwoStringsDemo(Value) values('999999');
mysql> insert into compareTwoStringsDemo(Value) values('999888');
mysql> insert into compareTwoStringsDemo(Value) values('567433');
mysql> insert into compareTwoStringsDemo(Value) values('567433');
mysql> insert into compareTwoStringsDemo(Value) values('2345123');
以下是使用select语句显示表中所有记录的查询-mysql> select *from compareTwoStringsDemo;
这将产生以下输出-+----+---------+
| Id | Value |
+----+---------+
| 1 | 1235667 |
| 2 | 999999 |
| 3 | 999888 |
| 4 | 567433 |
| 5 | 2345123 |
+----+---------+
5 rows in set (0.00 sec)
以下是查询以比较两个数字字符串-mysql> select *from compareTwoStringsDemo
-> where cast(Value as signed) = 999999;
这将产生以下输出。显示具有匹配字符串的记录-+----+--------+
| Id | Value |
+----+--------+
| 2 | 999999 |
+----+--------+
1 row in set (0.00 sec)