我需要在我的代码中执行“WHERE”过滤器,如下所示:
"select
round ((aust.DTH_DESENFORNAMENTO - aust.dth_enfornamento),7)*1440 as HF
from
qt_qts.res_tubo_austenitizacao aust
WHERE
HF between 'time1' and 'time2' <----------------- THE ERROR
")
但它表明在我的代码中无法识别HF。所以,我试图把全名(aust.DTH_DESENFORNAMENTO - aust.dth_enfornamento)并且它起作用了......但是,我需要把完整的表达,将时间转换为秒((aust.DTH_DESENFORNAMENTO - aust.dth_enfornamento) ),7)* 1440)。这样,出现错误,表达的原因。
我正在使用ORACLE数据库
如何在代码中没有错误的情况下参考HALF时间?
在给定的SELECT
子句中定义的别名在同一级别的WHERE
子句中不可用,因为后者在前者之前执行。这里有两个选择:您可以重复指定HF
别名的表达式,也可以重复子查询。这是第一个选择:
SELECT
ROUND((aust.DTH_DESENFORNAMENTO - aust.dth_enfornamento),7)*1440 AS HF
FROM qt_qts.res_tubo_austenitizacao aust
WHERE
ROUND((aust.DTH_DESENFORNAMENTO - aust.dth_enfornamento),7)*1440
BETWEEN 'time1' AND 'time2';
这是子查询选项:
WITH cte AS (
SELECT
ROUND((aust.DTH_DESENFORNAMENTO - aust.dth_enfornamento),7)*1440 AS HF
FROM qt_qts.res_tubo_austenitizacao aust
)
SELECT HF
FROM cte
WHERE HF BETWEEN 'time1' AND 'time2';