-
如图中表的数据,除去id、account_type字段不同,其余字段均相同
需求:
- 删除account_type=7的数据
实现
- 首先挑选出表中所有符合条件的数据
sql1 = 'select cost,media_account_id,dt,COUNT(media_account_id) as id,COUNT(cost) as cost,count(dt) as dt FROM media_account_daily_middle where media_id=201 ' \
'GROUP BY media_account_id,media_account_id,dt HAVING id>1 and cost>1 and dt>1'
result = mysql_mgr.select(sql1)
print(result)
- 对每条符合条件对数据进行删除操作
for item in result:
media_account_id = item.get('media_account_id')
dt = item.get('dt')
print(media_account_id)
del_sql = "delete from media_account_daily_middle where media_id=201 and account_type=7" \
" and media_account_id='%s' and dt = '%s' " % (media_account_id, dt)
api_db_cursor.execute(del_sql)
api_db_conn.commit()