0

This is my sql code

SELECT qty, unitprice, qty * unitprice as Stock FROM item

Form this i want to get the SUM of Stock

3
  • Did you try SUM(qty*unitprice) by using group by. Commented Feb 22, 2014 at 1:30
  • yes tried...but it is not working Commented Feb 22, 2014 at 1:39
  • Try calculating just the sum using SELECT SUM(qty*unitprice) as stock FROM item. Commented Feb 22, 2014 at 1:51

1 Answer 1

2

It is not clear what you are asking here. I'm not sure about the ultimate goal you are trying to achieve, but this will bring you SUM of all qty * unitprice :

SELECT qty, unitprice, SUM(qty * unitprice) as Stock FROM item

And this is literally bring you SUM of Stock :

SELECT SUM(Stock) as SUM_OF_STOCK
FROM 
    (SELECT qty, unitprice, qty * unitprice as Stock 
     FROM item)

If none of above query fit your needs, I think you really need to edit the question and elaborate more on what you are trying achieve.

Sign up to request clarification or add additional context in comments.

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.