mysql - 将a列值更新为与python中特定id对应的b列

标签 mysql python-2.7

我编写了一个代码,使用 pymysql 从 mysql 数据库读取 2 列(raw_id、注释),它给了我字典列表。现在我想提取 id 值,存储它并使用记录级别的每个 raw_id 的注释列值更新评论列。谁能帮我解决这个问题吗?

db_data 包含:

[OrderedDict([(u'raw_id', u'52c00'), (u'notes', u'awesome')]), 
OrderedDict([(u'raw_id', u'54df0'), (u'notes', u'loved it')]),
OrderedDict([(u'raw_id', u'5cd00'), (u'notes', u'enjoyed')]),...]

我使用过的代码:

for row in db_data:
    text = row.values()
    r_id = text[0]
    update_sql = "update raw_data set review = notes where 
    customer_id = {0} and raw_id = {1}"
    res = sql_db.execute_write(update_sql, [inp_cust_id, r_id])
    print res

我遇到的错误:

TypeError: not all arguments converted during string formatting

最佳答案

for row in db_data:
    text = str(row.values())
    r_id = str(text[0])
    update_sql = "update raw_data set review = notes where 
    customer_id = {0} and raw_id = {1}"
    res = sql_db.execute_write(update_sql, [inp_cust_id, r_id])
    print res

试试这个

关于mysql - 将a列值更新为与python中特定id对应的b列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56561309/

相关文章:

mysql - 我知道 PIVOT 命令可以转换数据集,这是正确的方法吗?

java - MySQL:考勤监控应用程序问题

java - 如何在 python/java 中使用 Selenium 访问 Chrome 开发工具网络选项卡的请求或摘要的值?

python - 使用 pandas 在 python 中读取 Excel 文件

mysql - 生成 mysql id 作为字符串而不是整数

PHP 将类对象数组绑定(bind)到列表

MYSQL 使用空间索引

python - 当我尝试使用一个函数来替换幂函数时不断收到错误,即当提高到 1/2 时

Python(金字塔框架)在请求之间保留数据,我不明白为什么

Python:使用 import 将常用函数添加到类中