Skip to content
Advertisement

how to select non repeated date intervals?

My products table,

My Query,

My output,

expected result,

I’m not getting any clue for generating that date interval. Any tips and suggestion of query will be of great help. Thanks

Advertisement

Answer

You can subtract a modulus 5 from the year and group by that.

A modulus N is the remainder when the nearest lower multitude of N is substracted from a number.
For example:

So by subtracting it from the year you get the nearest multitude of 5

Another way to round the year down is to divide & multiply it by 5

A test on db<>fiddle here

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