0

Lets says I got a table like this -

 id  |  name  |  salary
 01  |  ABCD  |  1000
 02  |  EFGH  |  2000    
 03  |  IJKL  |  3000

Now is it possible to get result set like this?

id  |  name  |  salary | SUM
01  |  ABCD  |  1000   | 6000
02  |  EFGH  |  2000
03  |  IJKL  |  3000

I tried SELECT id, name, salary, SUM(salary) FROM table but it just gives me one row. Is there any way to get all the rows with an extra column ?

1

2 Answers 2

1

Try:

SELECT id, name, salary, SUM(salary) AS sum FROM table

EDIT: Think i misunderstood. Maybe this is what you're looking for:

SELECT id, name, salary (SELECT SUM(salary) FROM table) AS sum FROM table
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT
  id,
  name,
  salary,
  (SELECT SUM(salary) FROM table)
FROM
  table

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.