1

I am stuck here, I have to display sum of each share of specific share group by symbol I have tried a lot but could not get it how can I display them in the html.This is my index.py code right now, I am using loop to display each symbol separately.

1 Answer 1

3

I think I know what you are after. You could try your SQL as something like this:

SELECT stocks, price, SUM(shares) as total_shares, SUM(shares) * price AS total  
FROM porfolio WHERE user_id = ii GROUP BY stock ORDER BY stock

I tested this so it should work.

I removed you " * " when making the SELECT statement because the 'shares' columns would contradict the new 'total_shares' column.

Let me know if you need clarification on my code.

2
  • And then I would display them in html by using the loop?
    – Ahmed Raza
    Commented Apr 5, 2017 at 7:27
  • Made some changes and it is working fine now, Thanks for the help.
    – Ahmed Raza
    Commented Apr 5, 2017 at 7:58

You must log in to answer this question.

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