Difference in columns

From: "Mag Gam" <magawake(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Difference in columns
Date: 2008-05-11 17:37:52
Message-ID: 1cbd6f830805111037m488f7051i7924060a1640fff4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi All,

I have a view that generates output similar to this.

select * from foo.view;

ts | size
-------------------+-----
2002-03-16 | 11
2002-03-17 | 16
2002-03-18 | 18
2002-03-19 | 12

I am trying to find the difference between the size column. So the desired
output would be

ts | size| Diff
-------------------+-----+------
2002-03-16 | 11 | 0
2002-03-17 | 15 | 4
2002-03-18 | 18 | 3
2002-03-19 | 12 | -6

I need the first column to be 0, since it will be 11-11. The second colum is
15-11. The third column is 18-15. The fourth column is 12-18.

Any thoughts about this?

TIA

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message chester c young 2008-05-11 17:54:38 Re: Difference in columns
Previous Message Christian Kindler 2008-05-09 15:00:34 Re: execute plpgsl like "normal" sql