题目如下:
Num
1
2
4
6
7
8
10
11
13
写条SQL语句转成下表:
Column1 Column2
1 2
4 4
6 8
10 11
13 13
答案:
selectMIN(Num),MAX(Num)from
(selectROW_NUMBER()over (orderbyNum)rk,NumFromNumbers)A
Groupby (A.rk-A.Num)
orderbyMin(Num)