Mysql 批次号不会增加
** 我试着查询名字的前三个字母 用于生成自动增量 ** 我尝试了这段代码,但输出错误。这里出了什么错Mysql 批次号不会增加,mysql,Mysql,** 我试着查询名字的前三个字母 用于生成自动增量 ** 我尝试了这段代码,但输出错误。这里出了什么错 SET @ndx = 0; SET @cur_hash = ''; SELECT id,Firstname ,CONCAT(left(Firstname ,3),IF(ndx>=0,CONCAT('--00',ndx),'')) BatchNumber FROM (SELECT id, @new_hash := MD5(Firstname ), (@ndx := IF(@ne
SET @ndx = 0;
SET @cur_hash = '';
SELECT id,Firstname ,CONCAT(left(Firstname ,3),IF(ndx>=0,CONCAT('--00',ndx),'')) BatchNumber
FROM (SELECT id,
@new_hash := MD5(Firstname ),
(@ndx := IF(@new_hash=@cur_hash,@ndx+1,1)) ndx,
@cur_hash := MD5(Firstname ),
Firstname
FROM (SELECT id,Firstname FROM sample ORDER BY Firstname ) AA) A order by id;
但我需要这种类型的输出:
Firstname | Batchnumber
---------------------
Anish | Ani001
Anish | Ani001
Uma | Uma001
Anish | Ani001
Uma | Uma001
temp | tem001
当名称被多次插入时,我增加了批号。但它不起作用。
我自己会努力找到答案,但这对我来说很难。有人能解决吗?我没有发现你的问题。我没有发现你的问题。看见
Firstname | Batchnumber
---------------------
Anish | Ani001
Anish | Ani001
Uma | Uma001
Anish | Ani001
Uma | Uma001
temp | tem001
Firstname | Batchnumber
-----------------------
Anish | Ani001
Anish | Ani002
Uma | Uma001
Anish | Ani003
Uma | Uma002
temp | tem001