From: Andy Colson <andy@squeakycode.net>
To: pgsql-general@postgresql.org
Subject: Re: Recursive CTE
Date: Sun, 30 Dec 2018 09:45:07 -0600
Message-ID: <8c11bb53-5596-c24f-e997-1485123a2026@squeakycode.net> (raw)
In-Reply-To: <CAE-4=KHD=VYL06WyCtRL-pRhtgUGyNrOR_98A=vKmXf9i5RuOA@mail.gmail.com>
References: <CAE-4=KHD=VYL06WyCtRL-pRhtgUGyNrOR_98A=vKmXf9i5RuOA@mail.gmail.com>
On 12/29/18 12:34 PM, Glenn Schultz wrote:
> All,
> Following my earlier post on variable instantiation, I rethought how I was working with dates and realized I can fix the date and use static interval. I came up with this recursive CTE which is the end goal. However, the problem is that the convexity query cannot be used as a subquery. So I think I need to use a join of convexity on the original query - not sure I am little stuck at this point but I feel I am close. Any help would be appreciated.
>
> -Glenn
If you are trying to find month summaries, then maybe date_trunc would be easier:
select date_trunc('month', fctrdt),
round(smmtocpr(cast(sum(currrpb * case when fnmloan.fctrdt = fnmloan_data.fctrdt then fnmloan_data.event else 0 end)/ sum(currrpb) as numeric) * 100),4) * 100 as "CPR 3mo"
from fnmloan
group by date_trunc('month', fctrdt)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: andy@squeakycode.net
Subject: Re: Recursive CTE
In-Reply-To: <8c11bb53-5596-c24f-e997-1485123a2026@squeakycode.net>
References: <CAE-4=KHD=VYL06WyCtRL-pRhtgUGyNrOR_98A=vKmXf9i5RuOA@mail.gmail.com> <8c11bb53-5596-c24f-e997-1485123a2026@squeakycode.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox