python操作sql
阿新 • • 發佈:2018-10-11
date_time 所有 convert advertise argument form int uri err
一、一次性更新多條記錄
‘UPDATE table_a SET impression=%s,click=%s,ctr=%s,cost=%s,update_time=%s WHERE date=%s AND campaign_id=%s‘
二、一次性新增多條記錄
‘INSERT INTO table_a(date,campaign_name,campaign_id,impression,click,ctr,cost,advertiser_id,add_time,update_time) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)‘
三、判斷表中是否存在某條記錄
‘SELECT EXISTS(SELECT * FROM table_a WHERE date="{}" and campaign_id={})‘.format(format_date, str(campaign_id))‘
註意:SQL語句中所有的占位符都要用%s,不然會報錯“MySQLdb TypeError: not all arguments converted during string formatting”
python操作sql