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 My goal is to collect data based on the time interval, and it indicates which code 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: As soon as you have a new column Please also check this. date_from related to each
date_to (excluding the last course):
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
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;
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.
Comments
Post a Comment