sql - Oracle 查询 - 结果中的更多记录与表中一样
问题描述
我想选择带有附加行(030)的数据表单表,它应该包含其他列的所有可能组合
例如:
Select * from table where row in ('010,'020','030')
comp period row column value
1 30.06.2017 010 020 500
1 30.06.2017 020 020 300
2 30.06.2017 010 020 400
3 30.06.2017 020 020 100
结果应该是这样的
comp period row column value
1 30.06.2017 010 020 500
1 30.06.2017 020 020 300
2 30.06.2017 010 020 400
2 30.06.2017 020 020 (null)
3 30.06.2017 020 020 100
3 30.06.2017 010 020 (null)
1 30.06.2017 030 020 (null)
2 30.06.2017 030 020 (null)
3 30.06.2017 030 020 (null)
解决方案
使用 across join
生成行,然后left join
引入当前结果。我想你想要:
Select cpr.*, r.row, t.value
from (select distinct comp, period, column from t) cpr cross join
(select '010' as row from dual union all
select '020' as row from dual union all
select '030' as row from dual
) r left join
t
on t.comp = cpr.comp and t.period = cpr.period and t.column = cpr.column and t.row = cpr.row;
推荐阅读
- php - 如何重定向到具有 owl carouselin 的不同 html 页面的特定部分
- base64 - 从 base64 字符串解码后无法取回 DICOM 元数据
- sql - 如何根据替换表替换字符?
- html - 如何在右侧创建响应式图像和按钮?
- python - Python Selenium 在成功获取结果后总是会打开一个额外的窗口
- asp.net-core-mvc - 如何通过自定义图标更改传单地图的图标
- javascript - 我在使用 setInterval 时遇到问题
- javascript - Array.map() 如何与反应组件一起使用?
- selenium-webdriver - 未发现此类元素异常
- javascript - 我的 Promise 捕获到异常,但我不知道如何打印错误消息