简体   繁体   English

如何计算mysql中两个字母数字字符串之间的差异

[英]how to calculate the difference between two alphanumeric strings in mysql

In the above picture stud_roll1 is the starting rollno and stud_roll2 is the ending上图中stud_roll1为起始rollno,stud_roll2为结束
rollno.How can I calculate the between rollno. rollno.How 如何计算 rollno 之间的值。 Ex: 16un01 is stud_roll1 and 16un04 is the ending rollno the result for my question is 16un01,16un02,16un03,16un04.例如:16un01 是stud_roll1,16un04 是结尾rollno 我的问题的结果是16un01,16un02,16un03,16un04。 How can I get the result?我怎样才能得到结果?

Try with this:试试这个:

SET @first_value = (SELECT SUBSTRING("16un01", 5,2));
SET @second_value = (SELECT SUBSTRING("16un04", 5,2));
SET @counter = @first_value;
WHILE @counter <= @second_value DO
    SELECT CONCAT("16un",LPAD(@counter,2,"0")) 16un;
    SET @counter = @counter + 1;
END WHILE;

I make a stored procedure on @first_value and @second_value you can obtain minimum and maximum (Obviously with a query), i divided the string and put into a value.我在@first_value 和@second_value 上创建了一个存储过程,您可以获得最小值和最大值(显然是通过查询),我将字符串分割并放入一个值中。 On While I make the values for the range put in into a stored procedure and run it, the values will be 16un01, 16un02, 16un03, 16un04当我将范围的值放入存储过程并运行它时,值将是16un01、16un02、16un03、16un04

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM