Select records between two dates with pre-established minute intervals

0

I have a table that stores data collected at 5-minute intervals. I would like to select the records between a start date / time and end date / time. Until then I can do it. But I would like to include a third parameter in the query that would be the time interval between collections. Ex. Records from 30-01-2018 00:00:00 to 30-01-2018 12:00:00 in 10-minute intervals.

    
asked by anonymous 30.01.2018 / 14:41

1 answer

-1

Enter the following clause in the WHERE:

DATEPART(MINUTE,[CAMPO DATA]) % 10 < 5

Explaining what is being done: I am isolating the last digit of the minute from its datetime field and verifying that it is contained in {0,1,2,3,4}. With that I believe it will return the expected values. Example (items in bold will be returned:

  • 01/30/2018 08:00
    1/30/2018 8:05 AM 30/01/2018 08:11
    1/30/2018 08:17
    1/30/2018 8:23 AM
    1/30/2018 8:28 AM 30/01/2018 08:33
    1/30/2018 8:38 PM

The table has only two fields:
datehora (datetime) tag (varchar (30)
Table contents:
datahora tag
2016-04-01 00: 01: 03.580 PDT_1_T13 @ PV
2016-04-01 00: 06: 03.580 PDT_1_T13 @ PV
2016-04-01 00: 11: 03.580 PDT_1_T13 @ PV
2016-04-01 00: 16: 03.580 PDT_1_T13 @ PV
2016-04-01 00: 21: 03.580 PDT_1_T13 @ PV
If the selection is 01-04-2016 00:00:00 until 01-04-2016 00:35:00
10-minute interval. Home Expected Exit
datahora tag 2016-04-01 00: 01: 03.580 PDT_1_T13 @ PV
2016-04-01 00: 11: 03.580 PDT_1_T13 @ PV
2016-04-01 00: 21: 03.580 PDT_1_T13 @ PV

    
30.01.2018 / 14:50