嘿伙计们,我真的可以使用一些帮助来编码这个 IF 语句!我设法适应了 2 个条件,但不确定第 3 个(计算)如何适应。这是伪代码中的 calc;
IF Producer_Type = 'Oil', Unallocated OIL&GAS = UnallocatedLossesOIL
IF Producer_Type = 'Gas', Unallocated OIL&GAS = UnallocatedLossesGAS
ELSE Unallocated OIL GAS = UnallocatedLossesOIL(MPPOil ÷ (MPPOil + MPPGas)) +
UnallocatedLossesGAS(MPPGas ÷ (MPPOil + MPPGas))
这是我的代码:
SELECT qb1.CompanyName, qb1.AssetName, qb1.Year,
IIf(qb1.Producer_Type='Oil',qb1.DatapointValue, qb2.DatapointValue) AS UnallocatedOilGas
FROM PEBaseQuery AS qb1 INNER JOIN PEBaseQuery AS qb2 ON qb1.Assetname=qb2.AssetName
WHERE qb1.DatapointID=2026 And qb2.DatapointID=2027;
其中 2026 的 DatapointID 是 UnallocatedLossesOIL,而 2027 是 UnallocatedLossesGAS。计算需要参考 MPPOil 和 MPPGas 值(与特定公司/资产/年份相关,它们是来自两个单独查询的结果......任何帮助将不胜感激!抱歉,如果其中一些没有意义......