sql 中的转换问题 - GREATEST(CEILING())
下面一个工作正常,浮点值。
import mysql.connector
conn = mysql.connector.connect()
cur = conn.cursor()
cur.execute('SELECT GREATEST(CEILING(Tot_Weight + 3.4),4.5) FROM TestTable order by id asc;')
print(cur.fetchall())
如果将参数传递给查询,则面临转换问题。尝试了 str(Wt1) 和 str(Wt2),但不行。
Wt1 = 7.02
Wt2 = 5.4
cur.execute('SELECT GREATEST(CEILING(Tot_Weight +'+ Wt1 +')', Wt2 +') FROM TestTable order by id asc;')
print(cur.fetchall())
TypeError: can only concatenate str (not "float") to str