Oracle添加顺序查询行,如果丢失
在Oracle 19c中,我有一个数据,例如:
with t as (
select 1 Cat, 1 id, 11 val from dual
union all
select 1, 3, 33 from dual
union all
select 2, 2, 22 from dual
union all
select 2, 4, 44 from dual)
select *
from t
在查询结果中,我想获得4
每个cat
带有IDS 1-4的行,如果没有这样的id
cat
a val
必须为null:
cat | id | val |
---|---|---|
1 | 1 | 11 |
1 | 2 | |
1 | 3 | 33 |
1 | 4 2 1 | |
2 | 2 | |
2 | 2 | 2 2 2 2 |
2 2 2 | 2 3 | |
2 | 4 | 44 44 |
In Oracle 19c I have a data like:
with t as (
select 1 Cat, 1 id, 11 val from dual
union all
select 1, 3, 33 from dual
union all
select 2, 2, 22 from dual
union all
select 2, 4, 44 from dual)
select *
from t
In query result I want to get 4
rows per every cat
with ids 1-4 and if there was no such id
in that cat
a val
must be null:
cat | id | val |
---|---|---|
1 | 1 | 11 |
1 | 2 | |
1 | 3 | 33 |
1 | 4 | |
2 | 1 | |
2 | 2 | 22 |
2 | 3 | |
2 | 4 | 44 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
分区
与行生成器加入:输出:
db< >
Use a
PARTITION
ed join with a row-generator:Which outputs:
db<>fiddle here