From: | Mike Martin <redtux1(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Question about getting values from range of dates |
Date: | 2018-06-22 10:32:15 |
Message-ID: | CAOwYNKY+Siukf6G81BZg4hfrBsReTR43DSMi3EfwU3T11b5qmA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
I am looking for suggestions about the best way to resolve this problem.
Scenario
I have entries for files in database which lack specific values (xml files
not generated)
These values can be obtained by what are called DTC read files, where the
values are the same in the last DTC read file before date of file and the
next DTC read file (by date)
This code works but looks horrendous, so would appreciate any ideas.
thanks
Mike
select max(a.recordingdate) ,max(b.recordingdate)
,a.registration,max(b.filename)
from create_tdms a
join (select registration,recordingdate,filename from create_tdms where
filename not like 'DTC%') b
on b.registration=a.registration
where b.recordingdate<a.recordingdate and a.filename like 'DTC%'
group by a.registration
union
select max(a.recordingdate) ,max(b.recordingdate)
,a.registration,max(b.filename)
from create_tdms a
join (select registration,recordingdate,filename from create_tdms where
filename not like 'DTC%') b
on b.registration=a.registration
where b.recordingdate>a.recordingdate and a.filename like 'DTC%'
group by a.registration
From | Date | Subject | |
---|---|---|---|
Next Message | Thiemo Kellner | 2018-06-22 12:05:56 | Re: Question about getting values from range of dates |
Previous Message | Moreno Andreo | 2018-06-22 08:46:01 | Re: pgp_sym_decrypt() - error 39000: wrong key or corrupt data |