How can I loop through all rows of a table? (MySQL)

后端 未结 5 1073
情深已故
情深已故 2020-11-27 10:56

I have a table A and there is one primary key ID.

Now I want to go through all rows in A.

I found something like \'for each record in A\', but this seems to

5条回答
  •  爱一瞬间的悲伤
    2020-11-27 11:33

    You should really use a set based solution involving two queries (basic insert):

    INSERT INTO TableB (Id2Column, Column33, Column44)
    SELECT id, column1, column2 FROM TableA
    
    UPDATE TableA SET column1 = column2 * column3
    

    And for your transform:

    INSERT INTO TableB (Id2Column, Column33, Column44)
    SELECT 
        id, 
        column1 * column4 * 100, 
        (column2 / column12) 
    FROM TableA
    
    UPDATE TableA SET column1 = column2 * column3
    

    Now if your transform is more complicated than that and involved multiple tables, post another question with the details.

提交回复
热议问题