Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
selectステートメントの結果で省略された行を埋める方法はありますか?
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経由でこれを行う方法はありますか?
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);