0

Right now I have made two tables to store user data and all transactions what users made. Structure of transaction table looks like this:

id          user        symbol      price       quantity    total       name                  type
----------  ----------  ----------  ----------  ----------  ----------  --------------------------  ----------------
     1       user1     A           55.43       2           110.86      Agilent Technologies, Inc.           buy             
     1       user1     A           53.25       3           159.75      Agilent Technologies, Inc.          buy  

With query SELECT * WHERE user = 'user1' i can select all transactions user1 made, but how can I combine these two rows in one and quantities sums up? Is this even possible in SQL?

0

You would use the aggregate function SUM(). A simple example would be:

SELECT sum(quantity) from transactions where .....

  • You can sum multiple columns like SELECT sum(quantity), sum(total) from ....
  • The "result" column name would be accessed like row["sum(quantity)"]

This should be enough to get you started, you will likely have to experiment to get exactly what you want.

You must log in to answer this question.

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