I looked up this answer in numerous forums and none seem to solve my problem. I am looking for a bit of help.
I want to take the average of numbers in a SQL database and display the average in HTML. I am using Flask, Python, SQL, and HTML.
Here is my PYTHON code:
avg_hours = db.execute("SELECT CAST(AVG(hours) AS int) FROM pain WHERE user_id = ?", user_id)
My HTML code:
{% for row in avg_hours %}
<h4>Average Hours: {{ row }} </h4>
{% endfor %}
But it displays like this on the html page:
Average Hours: {'CAST(AVG(hours) AS int)': 11}
How do I get it to display just the number? I want the display to show
Average Hours : 11
Any help would be appreciated