Skip to content
Advertisement

Get monthly sum/agv/max of a measurement from timestream

I am storing measurements in Timestream with the following attributes (example):

Let’s assume these metrics are written one per day. How do I have to query the data in order to get a monthly sum on the request count metric for a specific domain?

In order to get a sum for the whole time range queried I can do this:

This returns a total of the range specified. Is there a way to get the the total per month (via GROUP BY or similar)?

Advertisement

Answer

You can truncate a timestamp to different precisions using date_trunc in most SQL languages, AWS Timestream included.

In your case, you want to truncate time to a monthly precision: date_trunc('month', time). You can then group by this variable and sum request_count.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement