Returning an array of values from timestamps between a start and end time

hov

I have a query that produces a timestamp and a value at that timestamp.

select timestamp, value
from table1;

So, a sample from the data would look like this:

      timestamp      |     value      |
---------------------------------------
 2019-02-28 01:00:00 | 1              |
 2019-02-28 01:10:00 | 1              |
 2019-02-28 01:20:00 | 6              |
 2019-02-28 01:30:00 | 17             |
 2019-02-28 01:40:00 | 4              |
 2019-02-28 01:50:00 | 4              |

I have a second query that produces a start timestamp and an end timestamp.

select start, end
from table2;

A sample from that would look like this:

       start        |         end         |
-------------------------------------------
2019-02-28 01:00:00 | 2019-02-28 01:30:00 |
2019-02-28 01:40:00 | 2019-02-28 01:50:00 |

How would I be able to combine the two queries to produce an output like this?

       start        |         end         |      values     |
-------------------------------------------------------------
2019-02-28 01:00:00 | 2019-02-28 01:30:00 | {1,1,6}         |
2019-02-28 01:40:00 | 2019-02-28 01:50:00 | {4}             |
Gordon Linoff

Aggregation and join:

select t2.start, t2.end, array_agg(t1.value)
from table2 t2 left join
     table1 t1
     on t1.timestamp >= t2.start and t1.timestamp < t2.end
group by t2.start, t2.end;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Filter Array or XML with Time between Start and End Time

Rxjs Observable array select between given start and end values

Use start and end time to extract values from separate dataframe

Finding the average time between an array of timestamps in javascript

Add values from second dataframe if datetime is between start and end datetimes

mysql: get running count over time based on start and end timestamps

Determine if a given time is between start and end time

Get time passed between multiple begin-end sets of timestamps

fill in values between the start and end of multiple values

Fill in values between different start and end values

time picker returning null value if start and end time both same

I am trying to check the room reservation from start time to end time between two dates using laravel

Finding the midpoint between values in a pandas datetime column and making a start and end time period column based on the midpoint

Calculate "Start" Time from "End" Time

Identify each hour between start and end time

Returning values from array separately

R calculate time within time interval between start End time

print time intervals between start time and end time using php

PHP Searching Array for Start and End point of values

R group variables in days calculated from interval between start and end time

extract records between given start and end time from multiple log files

check for null values while finding timestamps from date+time

Getting values between Start and End Dates in Table 1 From Table 2 in R

How to get accurate time from start to end

Show data if current time is between start and end time of json data

Calculate duration between start time and end time in typescript

PostgreSQL - Select Query between today's start time and end time

Excel Formula For Between Start Date and Time and End Date And Time

Select shift based on current time between start and end time

TOP Ranking

HotTag

Archive