これらのコード行は何をするのか説明していただけますか?
表1:INT、VARCHAR、FLOAT
ID Name value
---------------------------
1 a1 32116580
2 a2 50785384
3 a3 54327508
4 a4 61030844
;with coords(i,row,col,total,N) as (
select 1,1,1,N.N*(N.N+1)/2, N.N
from (select count(*) N from table1) N
union all
select i+1,
case when col+1>N then row+1 else row end,
case when col+1>N then row+1 else col+1 end,
total, N
from coords
where i<total
)
私with
は、より大きなクエリで使用するための補助ステートメントを作成する方法を提供していることを知っているので、使用する変数を宣言するようなものですが、その後は少し混乱しcase
ますrow and col
... また、なぜ2つある場合: case when col+1>N then row+1 else
、SQLはどのように知っていますかwhen to do one case or the other
?...
i row col total N
--------------------
1 1 1 10 4
2 1 2 10 4
3 1 3 10 4
4 1 4 10 4
5 2 2 10 4
6 2 3 10 4
7 2 4 10 4
8 3 3 10 4
9 3 4 10 4
10 4 4 10 4