search

Home  >  Q&A  >  body text

php - How to make mysql add the corresponding count values ​​when inserting data with the same key?

cur.execute('insert into keywords(keywords, count) values(%s,%s)', (key, from_url_dict[key]))

{key1:10,key2:100}
{key1:30,key3:100}
The front is key, and the corresponding back is count
How to make mysql insert data when there is a key phase At the same time, the corresponding count values ​​are added?

天蓬老师天蓬老师2748 days ago394

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-16 13:11:32

    insert into keywords(keywords, count) values(%s,%s) ON DUPLICATE KEY UPDATE count = count +1;

    reply
    0
  • Cancelreply