如何在MySQL中选择以特定值开头的记录?
要选择以特定值开头的记录,您需要使用LIKE运算符。让我们首先创建一个表-
mysql> create table DemoTable690( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserValue varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable690(UserValue) values('567890');
mysql> insert into DemoTable690(UserValue) values('789032');
mysql> insert into DemoTable690(UserValue) values('567342');
mysql> insert into DemoTable690(UserValue) values('890678');使用select语句显示表中的所有记录-
mysql> select *from DemoTable690;
这将产生以下输出-
+--------+-----------+ | UserId | UserValue | +--------+-----------+ | 1 | 567890 | | 2 | 789032 | | 3 | 567342 | | 4 | 890678 | +--------+-----------+ 4 rows in set (0.00 sec)
以下是查询以选择以特定值开头的记录的查询-
mysql> select *from DemoTable690 where UserValue LIKE '567%';
这将产生以下输出-
+--------+-----------+ | UserId | UserValue | +--------+-----------+ | 1 | 567890 | | 3 | 567342 | +--------+-----------+ 2 rows in set (0.00 sec)
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短