Find Total Minutes Ignoring Overlap (Convert Cursor based Answer to CTE)

后端 未结 2 1333
忘掉有多难
忘掉有多难 2021-01-14 05:59

There is an existing question that asked how to find how many minutes there are in multiple date ranges, ignoring overlaps.

The example data given is (userID isn\'t

2条回答
  •  醉梦人生
    2021-01-14 06:28

    I solved that (well, in a way) very efficiently by creating a dumb table having the date and time (accurate be the minute) in one column (PK) and a bit in the second. A '1' meant, the user is available and 0 meant, he/she's not.

    The rest is dead simple. I was sick of having to write endless complicated queries in trying to get the minutes in partly overlapping time ranges.

    In fact, this was for computing machine efficiency.

    I know this is not the real deal but the most simple solution I came up with. You might create a function/SP which creates that table..

提交回复
热议问题