Skip to content
Advertisement

Using time interval in table for select in another

I am using a MySQL data base with 2 tables:

In one table I have BatchNum and Time_Stamp. In another I have ErrorCode and Time_Stamp.

My goal is to use timestamps in one table as the beginning and end of an interval within which I’d like to select in another table. I would like to select the beginning and end of intervals within which the BatchNum is constant.

In my example below, I would like something like SELECT BatchNum , ErrorCode, Errors.Time_Stamp WHERE Erorrs.Time_Stamp BETWEEN beginning_of_batch and end_of_batch:

I am using an answer from a previous question:

Select on value change

to find BatchNum changes but I don’t know how to include this in another select to get the ErrorCodes happening within the interval defined by BatchNum changes.

Advertisement

Answer

I think you want:

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