基于mysql中的选择在插入过程中增加非自动增量字段

问题描述:

我正在使用select语句将记录从一个表插入另一个表.插入到的表具有一个新字段,该字段在每次更新时应增加一个,但不应是自动递增的字段,因为每次更新时每个记录组的编号都需要重新开始.如果使用的select语句选择42条记录,则新表将具有一个字段,该字段对于从1开始的每条记录递增1.下一组应再次将此字段设置为1,然后为所选的每个记录递增.这可能吗?我在查找要使用的语法时遇到了麻烦,因为我的大部分搜索只是找到有关自动增量键的结果.

I'm inserting records from one table into another table using a select statement. The table being inserted to has a new field that should be incremented by one in each update, but should not be an auto-increment field as the number needs to start again for each group of records per update. If the select statement being used selects 42 records, the new table would have a field that is incremented by 1 for each record starting with one. The next group should have this field at 1 again and then increment for each record that was selected. Is this possible to do? I'm having trouble finding the syntax to use as most of my searching just finds results about auto-increment keys.

INSERT into images (filename, imgpath, imagenumber)
SELECT filename, imgpath, 1+
FROM old_images
WHERE event_id = 20

这是表的简单示例,但是我想知道是否有一种方法可以直接在mySql中增加在图像表的imagenumber字段中添加的内容.

This is a simple example of the tables, but I'm wondering if there is a way to increment what is being put into imagenumber field in the images table directly in mySql.

使用类似的东西

SET @t1=0; 
INSERT into images (filename, imgpath, imagenumber) 
SELECT  filename, 
        imgpath, 
        @t1 := @t1+1 
FROM    old_images 
WHERE   event_id = 20