Group by with showing full rows in Postgresql I have a table like below with two columns A, B:

CREATE TABLE foo AS
SELECT * FROM ( VALUES
  (1,1),
  (1,1),
  (1,2),
  (1,2)
) AS t(a,b);


I want the result like below:

A B
1 1
1 1
sum B = 2

1 2
1 2
sum B = 4


How I can do it in PostgresSQL. Thanks everyone a lot.
You just want this

SELECT a,b,sum(b)
FROM foo
GROUP BY a,b;

 a | b | sum 
---+---+-----
 1 | 2 |   4
 1 | 1 |   2


If you don't want to reduce the row set, you can do this..

SELECT a,b,sum(b) OVER (PARTITION BY a,b)
FROM foo;

 a | b | sum 
---+---+-----
 1 | 1 |   2
 1 | 1 |   2
 1 | 2 |   4
 1 | 2 |   4