Running Count based on time range

  • I've been beating my head against this one for a while, so any tips are very much appreciated. It really seems like it shouldn't be this hard.

    I have data like what is shown in the "Data:" box in the picture below, and I would like to create a query that will return something like the "Goal:" box in the picture. I want a count of the distinct ID for records who's TimeStart is before the Time but who's TimeEnd is after.

    I have the Time field in another table, all I can think to do is a full outer join to the other table and maybe like a case when.

  • Can you please post the DDL (create table) script for the relevant tables, sample data as insert statements and the expected results?

    😎

    Further, can you also post the full output of this statement: SELECT @@VERSION

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply