Skip to content
Advertisement

Using generate_serires with partition by generate triple duplicate row

I have a table which look like this:

Each type has it own dt value but each type should have a consecutive 15 minute range dt. But some row are missing. So, I used generate_strings() to add date and partition by to do it based on each type column by using this:

which I generate datetime in dt column based on in min to max dt with a range of 15 minutes.

This is what I expect to get:

But what I got as a result is like the expected one but it return triple for each type and datetime.

E.g.

This also happened to type B as well.

So, from my query, what do I need to change to get the expected result?

Advertisement

Answer

You just want to run generate_series() over the aggregation:

The window functions start by adding the min and max value to each row. Then each row gets its own series.

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