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 ?

4

2 回答 2

1

尝试:

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

编辑:认为我误解了。也许这就是你要找的:

SELECT id, name, salary (SELECT SUM(salary) FROM table) AS sum FROM table
于 2013-11-14T20:02:51.273 回答
1
SELECT
  id,
  name,
  salary,
  (SELECT SUM(salary) FROM table)
FROM
  table
于 2013-11-14T20:08:05.313 回答