正在尝试使用条形图创建页面。我正在使用flask框架和mysql数据库。
@app.route("/grafiek")
def chart():
data = []
years = optimize_list(get_data("SELECT DISTINCT year FROM tbldata"))
print(years)
sql = "SELECT cast(sum(Number_employees) as signed) FROM tbldata"
sql += "WHERE year = (%s) GROUP BY year, month ORDER BY year, month ASC"
print(sql)
for year in years:
data_part = optimize_list(get_data(sql, year))
data.append(data_part)
print(data)
labels = optimize_list(get_data("SELECT DISTINCT month FROM faillisementen.tbldata"))
titels= "Number Employees in faillisementen"
colors = ['red', 'green']
return render_template("chart.html", data=data, labels=labels)
运行时出现错误:
getting data
SELECT cast(sum(Nulber_employees) as signed) FROM tbldata
not all arguments converted during string formatting
我假设错误与这些行有关:
sql = "SELECT cast(sum(Number_employees) as signed) FROM tbldata"
sql += "WHERE year = (%s) GROUP BY year, month ORDER BY year, month ASC"
请问我该怎么修?
更新:当没有使用第二行(%s)时,我得到错误“在字符串格式化期间没有转换所有参数”。当这条线被使用时,我得到了一个不同的错误。
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= (2011) GROUP BY jaar, maand ORDER BY jaar, maand ASC' at line 1")
2条答案
按热度按时间vatpfxk51#
我找到了一种不同的方法将数据库中的数据输入到图表中。
不过还是谢谢你。
这使它变得容易多了。
wfveoks02#
可能是第二行中的(%s):
sql+=“其中年=(%s)按年分组,按年月订单,按月asc”
如果你移开那条线,它能用吗?
请参阅python mysqldb typeerror:并非所有参数都在字符串格式化期间转换