0

selectステートメントの結果で省略された行を埋める方法はありますか?

次のようなデータがあります。

person,day
1,20
1,24

...これは、次のような単純なクエリによって返されます。

select *
from example_table
where day>=20

結果が次のようになるように、不足している日数の行を追加したいです。

person,day
1,20
1,21
1,22
1,23
1,24

SQL経由でこれを行う方法はありますか?

4

1 に答える 1

0

1 つの解決策は、1 から最大値 (31?) までの値を持つ 1 つの整数列を持つヘルプ テーブルです。

select person, day
from yourtable
UNION ALL
select intcol, 
from helptable h
where not exists (select day from yourtable y where y.day = h.helptable);
于 2014-06-07T11:40:32.927 に答える