0

我只想从以下工作查询中选择 GAS < 0.9 和 oil < 0.9 的行。

下面的查询工作正常,但我无法检查以仅在 GAS < 0.9 和 oil < 0.9 值时进行选择,因为我已经在使用 groupby ;我不确定获得此结果的最佳方法是什么。

SELECT
         rf.DAYTIME,
         GEO_FIELD_CODE,
         f.NAME,
         ROUND(decode(THEOR_GAS_RATE_SM3, 0, NULL, NULL, NULL,ABS(ALLOC_GAS_VOL_SM3/THEOR_GAS_RATE_SM3)),3) AS GAS,
         ROUND(decode(THEOR_NET_OIL_RATE_STM3, 0, NULL, NULL, NULL,ABS(ALLOC_NET_OIL_VOL_STM3/THEOR_NET_OIL_RATE_STM3)),3) AS OIL
FROM (SELECT 
         DAYTIME,
         GEO_FIELD_CODE,
         SUM(THEOR_GAS_RATE_SM3) AS THEOR_GAS_RATE_SM3,
         SUM(ALLOC_GAS_VOL_SM3) AS ALLOC_GAS_VOL_SM3,
         SUM(THEOR_NET_OIL_RATE_STM3) AS THEOR_NET_OIL_RATE_STM3,
         SUM(ALLOC_NET_OIL_VOL_STM3) AS ALLOC_NET_OIL_VOL_STM3
    FROM XYZ
   WHERE DAYTIME >= TO_DATE ('2013-01-01', 'yyyy-mm-dd')
    GROUP BY DAYTIME, GEO_FIELD_CODE
ORDER BY GEO_FIELD_CODE, DAYTIME) rf, ECKERNEL_HALE.OV_FIELD f
WHERE rf.GEO_FIELD_CODE = f.CODE

任何帮助都感激不尽。

4

1 回答 1

0

我看到两种不同的方法来解决它。您可以使用用于计算条件中的值的表达式:

WHERE
  rf.GEO_FIELD_CODE = f.CODE AND
  ROUND(decode(THEOR_GAS_RATE_SM3, 0, NULL, NULL, NULL,ABS(ALLOC_GAS_VOL_SM3/THEOR_GAS_RATE_SM3)),3) < 0.9 AND
  ROUND(decode(THEOR_NET_OIL_RATE_STM3, 0, NULL, NULL, NULL,ABS(ALLOC_NET_OIL_VOL_STM3/THEOR_NET_OIL_RATE_STM3)),3) < 0.9

查询计划器应该足够聪明,可以看到它们是相同的表达式,因此它们实际上不会被计算两次。另一种选择是将整个查询包装在另一个查询中,以便您可以访问表达式的结果:

SELECT DAYTIME, GEO_FIELD_CODE, NAME, GAS, OIL
FROM (
  ... your current query goes here
) x
WHERE GAS < 0.9 AND OIL < 0.9
于 2013-09-06T14:55:41.690 回答