1

How can I make a query that adds and multiplies two columns?

For example:

id || Price per item || Items purchased
1  || 4------------------- ||     3
2  || 3.2----------------  ||     7

I need a query to do: 4*3 + 3.2*7 and so on... How can I do so?

Thank you!

2 Answers 2

5

Try this:

SELECT SUM(price * items_purchased)
  FROM myTable
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT *, SUM(price*items) total FROM your_table

It will save the sum in the field total. You can access it in your application with that reference, just like you would access price or items.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.