ohtaka ともうします
よろしくお願いします。
たぶん Database(SQL) をお使いでしょうから、発想を変えて固定行数を返すようにしたらどうでしょう。
Orcale12 での動作確認をしています。
他のDBでしたら from dual と nvl あたりの変更が必要と思います。
where seq_tbl.idx < 10 の数値を変更すれば固定行数が変えられます。
参考にしてみてください。
----
create table test_tbl (
key number(6),
idx number(4),
item varchar2(10)
);
insert into test_tbl values (1,1,'001-1');
insert into test_tbl values (1,2,'001-2');
insert into test_tbl values (2,1,'002-1');
insert into test_tbl values (2,2,'002-2');
insert into test_tbl values (2,3,'002-3');
insert into test_tbl values (3,1,'003-1');
with seq_tbl(idx) as (
select 1 as idx from dual
union all
select seq_tbl.idx+1
from seq_tbl
where seq_tbl.idx < 10
)
select A.key, A.idx, nvl(test_tbl.item, '') item
from (
select test_tbl.key key,
seq_tbl.idx idx
from seq_tbl, test_tbl
group by test_tbl.key, seq_tbl.idx
) A
left outer join test_tbl
on A.key = test_tbl.key
and A.idx = test_tbl.idx
order by A.key, A.idx
;
drop table test_tbl;
----
2020年6月2日火曜日 18時30分07秒 UTC+9 太田@Gracix: