0

I am doing pset9 finance and I am kind of stuck because whenever I buy for example FB stocks multiple times it doesn't sum up in to show in the index function.

this is the code:

@app.route("/")
@login_required
def index():
    rows = db.execute("SELECT symbol, shares, price FROM transactions WHERE user_id = :user_id GROUP BY user_id, symbol", user_id=session['user_id'])
updated_cash = db.execute("SELECT cash FROM users WHERE id=:id", id=session["user_id"])
    total = updated_cash

portfolio = []
for row in rows:
    portfolio.append(list((row['symbol'], row['shares'], (row['price']), row['price']*row['shares'])))

return render_template("index.html", portfolio=portfolio, total=total)
1

This sql SELECT symbol, shares, price FROM transactions WHERE user_id = :user_id GROUP BY user_id, symbol uses a group by. But there is no aggregate function for the "grouping". Read up on the sqlite aggregate functions; you are interested in sum and/or total.

1
  • thank you for your guidance :D
    – Arsham
    Mar 9 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .