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 ?

fthiella
  • 48,073
  • 15
  • 90
  • 106
skos
  • 4,102
  • 8
  • 36
  • 59

2 Answers2

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
Imbue
  • 399
  • 3
  • 14
1
SELECT
  id,
  name,
  salary,
  (SELECT SUM(salary) FROM table)
FROM
  table
fthiella
  • 48,073
  • 15
  • 90
  • 106