My table looks like this:
Table 1:
Note: This table is very large in reality, with lots more columns (20ish) and rows (in the millions)
| Time | tmp | productionID |
| 10:00:00 | 2.2 | 5 |
| 10:00:05 | 5.2 | 5 |
| 10:00:11 | 7.4 | 5 |
| ...... | 3.2 | 5 |
| 10:10:02 | 4.5 | 5 |
Note: Timeis a varchar, so I assume I need to do something like this:
CONVERT(VARCHAR(8), DATEADD(mi, 10, time), 114)
What I need to do is:
select time, tmp
from mytable
where productionid = somevalue
and time = first_time_stamp associated to some productionID(ie. 10:00:00 table above)
time = 10 minutes after the first_time_stamp with some productionID
time = 20 minutes after the first_time_stamp with some productionID
...25, 30, 40, 60, 120, 180 minutes
I hope this makes sense. I’m not sure what the right way to do this is. I mean I thought of the following proccess:
-select first time stamp (with some productionID)
-add 10 minutes to that that time,
-add 20 minutes etc.. then use a pivot table and use joins to link to table 1
There must be an easier way.
Thank you in advance for the expertise.
Sample output expected:
| Time | tmp
| 10:00:00 | 2.2
| 10:10:02 | 4.5
| 10:20:54 | 2.3
| 10:30:22 | 5.3
If you create an interval table on-the-fly and cross join it with starting time for each ProductionID, you can extract records fromMyTable falling in the same category and choose to retrieve only the first one.
Sql Fiddle here.