Re: Difference in columns
От
Gurjeet Singh
Тема
Re: Difference in columns
Дата
Msg-id
65937bea0805111055q4945bb1bif677c2f1d4082d80@mail.gmail.com
Ответ на
Difference in columns (Mag Gam)
Список
Дерево обсуждения
Difference in columns "Mag Gam" <magawake@gmail.com>
Re: Difference in columns hubert depesz lubaczewski <depesz@depesz.com>
Re: Difference in columns Craig Ringer <craig@postnewspapers.com.au>
Re: Difference in columns "Gurjeet Singh" <singh.gurjeet@gmail.com>
Re: Difference in columns Tom Lane <tgl@sss.pgh.pa.us>
Re: Difference in columns Craig Ringer <craig@postnewspapers.com.au>
Re: Difference in columns "Mag Gam" <magawake@gmail.com>
Re: Difference in columns chester c young <chestercyoung@yahoo.com>
Re: Difference in columns "Gurjeet Singh" <singh.gurjeet@gmail.com>
On Sun, May 11, 2008 at 11:07 PM, Mag Gam <magawake@gmail.com> wrote:
Try this:
select ts,
size,
t1.size - (select t2.size
from foo.view as t2
where t2.ts < t1.ts
order by ts desc
limit 1) as diff
from foo.view as t1
order by ts asc;
HTH,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
EnterpriseDB http://www.enterprisedb.com
Mail sent from my BlackLaptop device
Hi All,
I have a view that generates output similar to this.
select * from foo.view;ts | sizeI am trying to find the difference between the size column. So the desired output would be
-------------------+-----
2002-03-16 | 11
2002-03-17 | 16
2002-03-18 | 18
2002-03-19 | 12ts | 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?
Try this:
select ts,
size,
t1.size - (select t2.size
from foo.view as t2
where t2.ts < t1.ts
order by ts desc
limit 1) as diff
from foo.view as t1
order by ts asc;
HTH,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
EnterpriseDB http://www.enterprisedb.com
Mail sent from my BlackLaptop device
В списке pgsql-sql по дате отправления