Reputation: 3229
im using a combination of flask and Jinja to return a template.
My SQL Statement is getting a list of "stocks" currently and looks like this:
stocks = db.execute("SELECT symbol,SUM(numshare),price FROM portfolio GROUP BY symbol")
return render_template("index.html",stocks=stocks)
and my HTML (Basic right now, just making sure I understand it first):
{% for stock in stocks %}
<p>{{stock.symbol}},{{stock.sum}},{{stock.price}}</p>
{% endfor %}
So it's returning the symbol and price of course, but I need to return the SUM of the numshare (Which is the number of shares bought for each "Stock". So im compounding them just for easier readability.
Is there a good way to do this? Keeping in my "table" might have multiples of the same stocks at different prices
Upvotes: 0
Views: 927
Reputation: 1807
MySQL is your issue
SELECT symbol,
SUM(numshare) AS sum,
price
FROM portfolio
GROUP BY symbol
Note: the AS
is not necessary, but you're writing in python. Be explicit.
Upvotes: 2