如何比较两个字符串在MySQL中是数字?
要比较MySQL中的两个数字字符串,请使用CAST()函数。
语法如下
select *from yourTableName where cast(yourColumnName as signed)=yourIntegerValue;
为了理解上述语法,让我们创建一个表。创建表的查询如下
create table compareTwoStringDemo -> ( -> UserId varchar(100) -> );
使用insert命令在表中插入一些记录。查询如下-
insert into compareTwoStringDemo values('1083745');
insert into compareTwoStringDemo values('9867585');
insert into compareTwoStringDemo values('3547483');
insert into compareTwoStringDemo values('9845646');
insert into compareTwoStringDemo values('9876532');使用select语句显示表中的所有记录。查询如下-
select *from compareTwoStringDemo;
以下是输出
+---------+ | UserId | +---------+ | 1083745 | | 9867585 | | 3547483 | | 9845646 | | 9876532 | +---------+ 5 rows in set (0.00 sec)
这是比较两个数字字符串的查询
select *from compareTwoStringDemo -> where cast(UserId as signed)=3547483;
以下是输出
+---------+ | UserId | +---------+ | 3547483 | +---------+ 1 row in set (0.00 sec)
热门推荐
10 学生开学季祝福语简短
11 求简短的职场祝福语
12 年月日祝福语简短
13 出阁祝福语简短句子
14 公司五一祝福语简短最新
15 关于开车的祝福语简短
16 收生日红包祝福语 简短
17 给婴儿祝福语简短的话
18 新年给妹妹祝福语简短