Skip to content
Advertisement

How can I select data from my database in time intervals?

Suppose I have the following table in a database:

Is there a way to use a select statement to grab the data in intervals? For example, selecting data in 2 minutes intervals so that records 0,2,4,6,8, and 10 would show? Something like:

Advertisement

Answer

You need DATEPART() and modulo (%):

DEMO

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