1.SQL语句:
SELECT * FROM `tb_user` where userName like '小%'; SELECT * FROM `tb_user` where userName like '%小%'; SELECT * FROM `tb_user` where userName like '%小'; SELECT * FROM `tb_user` WHERE userName LIKE '小'; SELECT * FROM `tb_user` where left(userName,1)='s'; SELECT * FROM `tb_user` where substring(userName,1,1)='s';
2.表结构:
CREATE DATABASE /*!32312 IF NOT EXISTS*/`testdb` /*!40100 DEFAULT CHARACTER SET utf8 */; USE `testdb`; DROP TABLE IF EXISTS `tb_user`; CREATE TABLE `tb_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userName` varchar(18) DEFAULT NULL, `birth` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; insert into `tb_user`(`id`,`userName`,`birth`) values (1,'小军','1993-06-05 00:00:00'), (2,'小明','1993-04-03 00:00:00'), (3,'呵呵','2020-12-13 17:43:16'), (4,'tt','2020-12-13 17:43:23'), (5,'ta','2020-12-31 17:45:44'), (6,'st','2020-12-13 17:45:53'), (7,'均小','2020-12-13 17:47:18');
3.查询效果: