Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我创建了包含 id、name、batch、rollnumber 列的用户表
我想创建一个存储过程,它将为每批生成卷号。
假设我有 100 名学生和五个批次(A、B、C、D、E)。
它应该在每批中生成卷号 1-20。
先感谢您
尝试这个:
SELECT u.id, u.name, u.batch, IF(@batch = (@batch := u.batch), @rollNo := @rollNo + 1, @rollNo := 1) rollNo FROM userTable u, (SELECT @batch:='', @rollNo:=1) A ORDER BY u.batch, u.name