在mysql查询中使用多个python变量

时间:2015-02-20 04:11:35

标签: python mysql

我试图在python的mysql查询中使用多个变量。第一个查询工作正常,但我在第二个查询中不断收到错误:1064: you have an error in your sql syntax: check the manual that corresponds to your MySQL server version for the right sytanx to use near ')) from database.table' at line 1

这是我的代码:

query = ("select count(*) from %s.%s;" % (databaseName, tableName))

cursor.execute(query)

for row in cursor.fetchall():

       print ("This is the total count: %d" % row)

query = ("select min(%s) from %s.%s;" % (columnName, databaseName, tableName))

result2 = cursor.execute(query)

for row in cursor.fetchall():

        print ("This is the min: %d" % row)

我想知道为什么第一个查询工作正常,但第二个问题是抛出语法错误?

0 个答案:

没有答案