PostgreSQL 9.2 Platform
I am very new to PostgreSQL. I have this script that I was able to address in MSSQL, but the same approach does not work with Postgres.
I have this table
CREATE TABLE TEST(
ID INT,
Value1 INT,
Value2 INT
);
INSERT INTO TEST
VALUES
(1,10,0),
(2,20,0),
(3,50,0),
(4,100,0),
(5,500,0);
I need the total number in a column Value2e.g.
UPDATE TEST
SET Value2 = T2.Value1-T1.Value1
FROM TEST T1
INNER JOIN TEST T2
ON T2.ID=T1.ID+1;
SELECT * FROM TEST;
While this works fine in MSSQL, it does not work in Postgres. The command succeeds, but no rows are updated.
However, when I try to do this, I see that the logic is correct
SELECT T2.ID,T2.Value1-T1.Value1
FROM TEST T1
INNER JOIN TEST T2
ON T2.ID=T1.ID+1;
What am I doing wrong here?
SQLFIDDLE DEMO
source
share