SQL self join multiple times

后端 未结 3 1333
庸人自扰
庸人自扰 2021-01-24 05:44

I have a single database table that stores week entries.

Id        Value     WeekId
1         1.0000    1
2         2.0000    1

There can be up

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 06:15

    You will need to add in your where clause the possibility that w2.Id is null or w3.id is null

    So something like

    WHERE 
      (w2.Id is null and w3.id is null) or 
      (w3.id is null and w1.id < w2.id) or 
      (w1.id < w2.id and w2.id < w3.id)
    

提交回复
热议问题