Re: summing tables
От | Greg Stark |
---|---|
Тема | Re: summing tables |
Дата | |
Msg-id | 878yqzn8k5.fsf@stark.dyndns.tv обсуждение исходный текст |
Ответ на | Re: summing tables ("Viorel Dragomir" <bigchief@vio.ro>) |
Список | pgsql-sql |
To solve this problem efficiently you probably need the lead/lag analytic functions. Unfortunately Postgres doesn't have them. You could do it with something like: update foo set c = a+b+(select c from foo as x where seq < foo.seq ORDER BY seq desc LIMIT 1) or the more standard but likely to be way slower: update foo set c = a+b+(select c from foo as x where seq = (select max(seq) from foo as y where seq < foo.seq)) However, i would suggest that if you have an implicit relationship between records you should make that relationship explicit with a foreign key. If you had a column that contained the seq of the parent record then this would be easy. I'm really puzzled how this query as currently specified could be useful. -- greg
В списке pgsql-sql по дате отправления: