Python MySQLdb iterate through table

前端 未结 2 1064
面向向阳花
面向向阳花 2021-02-07 13:53

I have a MSQL db and I need to iterate through a table and perform an action once a WHERE clause is met. Then once it reaches the end of the table, return to the top and start o

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-07 14:39

    Once you have results in the cursor, you can iterate right in it.

    cursor = database.cursor()    
    cursor.execute("SELECT user_id FROM round WHERE state == -1 AND state = 2")  
    for round in cursor:
      if round[0] != 5
        ...do stuff
    

提交回复
热议问题