创建一个具有普通数字自动增量ID的表,但要么用ZEROFILL,或使用LPAD若要在选择时添加零,请执行以下操作。然后CONCAT获取您预期行为的值。例1:create table so (
id int(3) unsigned zerofill not null auto_increment primary key,
name varchar(30) not null);insert into so set name = 'John';insert into so set name = 'Mark';select concat('LHPL', id) as id, name from so;+---------+------+| id | name |+---------+------+| LHPL001 | John || LHPL002 | Mark |+---------+------+
例2:create table so (
id int unsigned not null auto_increment primary key,
name varchar(30) not null);insert into so set name = 'John';insert into so set name = 'Mark';select concat('LHPL', LPAD(id, 3, 0)) as id, name from so;+---------+------+| id | name |+---------+------+| LHPL001 | John || LHPL002 | Mark |+---------+------+