oracle - Oracle - Selecting not null result of calculation
问题描述
For every row of my data set, there exist data for the only one of the two options for calculation and the other columns are Null.
My goal is to find simplest way to select not null result of calculation for each row. Expected result:
ROW_NUM result
-------- -------
1 4.5
2 4.56
My code:
With DATASET AS (
-- column 1 is just for row number,
-- column 2 and 3 for caculation option1,
--- columns 4~6 for caculation option2
SELECT 1 ROW_NUM, NULL time1, NULL qty1, 2 time2_1, 2.5 time2_2, 1 qty2
FROM DUAL
UNION
SELECT 2 ROW_NUM, 4.56 time1, 1 qty1, NULL time2_1, NULL time2_2, NULL qty2
FROM DUAL
)
SELECT ROW_NUM, time1/qty1 OPTION1, (time2_1+time2_2)/qty2 OPTION2
FROM DATASET;
Result:
ROW_NUM OPTION1 OPTION2
-------- ------- ---------
1 4.5
2 4.56
解决方案
推荐阅读
- python - Pandas:Dataframe itertuples 布尔系列 groupby 优化
- django - Factoryboy 无法生成依赖数据库的字段
- xamarin - Xamarin Forms 错误 APT1000:在应有项目的位置找到标记 id (Android)
- html - 如何使用 flex 并排修复此流程图与 Div(用于流程图步骤)和 Container(用于内容)对齐
- node.js - IBM Cloud Functions 和 Node.js:如何获取日本时间?
- r - 删除 geom_tile 中分隔样本的灰色垂直条纹
- haskell - 在 Haskell 中输出多个文件
- ios - 传递给结构的委托属性是否也应该在结构中声明为弱?
- android - 无法使用 DataBinding 隐藏 ProgressBar
- elasticsearch - 添加 Elasticsearch 排序返回不正确的结果?