Search Postgresql Archives

Re: Question about getting values from range of dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mike

Zitat von Mike Martin <redtux1@xxxxxxxxx>:

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.

Bit is formatted so little?

Sorry, I did not quite get the functional specification here, so I just put forward a technical optimised proposal. It seems to me equivalent to the following. Note I used Union ALL because the data sets of the two cases seem to be disjoint to me. The ALL makes PostgreSQL leave out the discarding process of identical rows (in the complete set, i. e. if there are identical rows in one part of the set they will be singled as well). Column aliasing is partly necessary partly to be clearer.

with BASE as
     (
            select a.recordingdate as recordingdate_a,
                   b.recordingdate as recordingdate_b,
                   a.registration  as registration_a,
                   b.filename      as filename_b
              from create_tdms        a
                     join (
                                 select registration,
                                        recordingdate,
                                        filename
                                   from create_tdms
                                  where filename not like 'DTC%') b
                       on b.registration = a.registration
             where a.filename         like 'DTC%'
     )
  select max (recordingdate_a) as max_recordingdate_a,
         max (recordingdate_b) as max_recordingdate_b,
         registration_a        as registration,
         max (filename_b)      as filename
    from BASE
   where recordingdate_b < recordingdate_a
group by registration_a
union all
  select max (recordingdate_a) as max_recordingdate_a,
         max (recordingdate_b) as max_recordingdate_b,
         registration_a        as registration,
         max (filename_b)      as filename
    from BASE
   where recordingdate_b > recordingdate_a
group by registration_a

Kind regards Thiemo

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux