aggregate functions - Time series in PostgreSQL - list changes -


I have a table in PostgreSQL with some time-series data, which is showing the change of values ​​in the parameter - we There can be no difference and there is date_from related to each date_to (excluding the last course):

  select date_from , Date_to, xx yy orders from date before date; Date_from | Date_to | Xx ----------- + ------------ + ------------------ 2014-05-01 | 2014-05-21 | 0/05/2014 | 2014-06-02 | 10 2014-06-02 | 2014-06-05 | 10 2014-06-05 | 2014-06-10 | 10 2014-06-10 | 2014-06-26 | 0 0 0 0 0 6 2014-07-01 | 10 2014-07-01 | 2014-07-08 | 10 2014-07-08 | 2014-07-23 | 0 2014-07-23 | 2014-08-04 | 10 2014-08-04 | 2014-08-20 | 10 2014-08-20 | 2014-09-02 | 20 2014-02-02 | 2014-09-03 | 20 2014-09-03 | 2014-09-22 | 02 2014-09-22 | 2014-09-24 | 10 2014-09-24 | 2014-10-02 | 20 2014-10-02 | 2014-10-08 | 20 2014-10-08 | Infinity | 0   

My goal is to collect data based on the time interval, and it indicates which code xx remains on a given value:

  from date_ | Date_to | Xx ----------- + ------------ + ------------------ 2014-05-01 | 2014-05-21 | 0/05/2014 | 2014-06-10 | 10 2014-06-10 | 2014-06-26 | 0 0 0 0 0 6 2014-07-08 | 10 2014-07-08 | 2014-07-23 | 0 2014-07-23 | 2014-08-20 | 10 2014-08-20 | 2014-09-03 | 20 2014-09-03 | 2014-09-22 | 02 2014-09-22 | 2014-09-24 | 10 2014-09-24 | 2014-10-08 | 20 2014-10-08 | Infinity | 0   

To present this data in a more compact way for some business users, I tried to use but I did not know how to separate those changes Is there any sign of anyone?

Thanks,

You can use the walking to create group identifier Total feature, such as:

  with yy (date_from, date_to, xx) AS (VALUES ('2014-05-01': Date, '2014-05-21': Date, 0), ('2014-05-21', '2014-06-02', 10), ('2014-06-02,' '2014-06-05', 10), ('2014-06-05 ',' 2014-06-10 ', 10), (' 2014-06-10 ',' 2014-06-26 ', 0), (' 2014-06-26 ',' 2014- 07-01 ', 10), ('2014-07-01', '2014-07-08', 10), ('2014-07-08', '2014-07-23', 0), ('2014-07-23 ',' 2014-08-04 ', 10), (' 2014-08-04 ',' 2014-08-20 ', 10), (' 2014-08-20 ',' 2014- 09-02 ', 20), ('2014-09-02', '2014-09-03', 20), ('2014-09-03', '2014-09-22', 0), ('2014-09-22 , '2014-09-24', 10), ('2014-09-24', '2014-10-02', 20), ('2014-10-02', '2014- 10-08', 20 ), ('2014-10-08', 'A Nantta, 0) Date from date, date, time, xx, amount (g) to date (date from date to date) GRP (selection date_, date_to, xx), when in case (xx) over (date Date from date) = xx then zero to 1 and g i.e. date from date;   

As soon as you have a new column grp , you can use it in GROUP BY . Note, that subcategory is needed, because in some other way the window can not refer to the results of the actions.

Please also check this.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -