You are reading a single comment by @aglet and its replies. Click here to read the full conversation.
  • The subjects might have had more than one occurrence unfortunately.

    The only way I can think to group them is to reference the row below.

    I could potentially use a for loop with this logic.

    Counter =0
    For i in number_of_rows:
      If enddate[i]+1 = startdate [i+1]:
        grp_num[i] = n
      elif:
        num = num+1
        grp_num[i] = num
    

    Any issues with doing loops in SQL? Will it kill everything?

  • Thanks. I think I'll try to group using LEAD() and apply a grouping number using DENSE_RANK().

About

Avatar for aglet @aglet started