Python2.7 + MySQL查询变量列返回变量值

标签 python mysql

我尝试发送此查询:

    data = ('name')
    query = ("SELECT %s FROM table")

    cursor.execute(query,[data])

并打印整数:

b = cursor.fetchall()
    for row in b:
        a = row[0]
        list_of_a.append(model)
    return list_of_a

    print list_of_a

并得到:

姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名 姓名

我尝试在其中进行查询(“从表中选择名称”)

我从“名称”列中得到:值1,值2,值3......等

最佳答案

像这样更改您的查询。

query = ("SELECT '%s' FROM table")

它会起作用。

关于Python2.7 + MySQL查询变量列返回变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992030/

相关文章:

python - SQLAlchemy IntegrityError 违反约束名称

python - Python 和一般情况下的浮点相等性

python - 计算我的 for 循环,并希望使用某些函数在没有 for 循环的情况下进行计算

mysql - 带连接的复杂查询,如何检索 COUNT

php - 合并两个 mysql 字段并使用 php 更新第三个字段

mysql - MariaDB 用户过程无限循环

python - 多参数函数 - *args/**kwargs 的正确用法

Python 请求 : how to GET and POST a picture without saving to drive?

php比较包含&的字符串

php - 如何将数组转换为带索引的字符串