sql中的一个表达式太长了,能取个别名,在表达式里用吗?
比如下面这个sql里trunc((T2.C700020016-T2.C700020015)/60/60/24,0))用了好几次,我想给他取个别名,但是不能作为sql的查询结果显示出来
select decode(trunc((T2.C700020016-T2.C700020015)/60/60/24,0),0,'00',CASE WHEN length(trunc((T2.C700020016-T2.C700020015)/60/60/24,0)))>1 then trunc((T2.C700020016-T2.C700020015)/60/60/24,0)) else ('0' || trunc((T2.C700020016-T2.C700020015)/60/60/24,0))) end || '天' || decode(trunc(mod((T2.C700020016-T2.C700020015),60*60*24)/60/60,0),0,'00',trunc(mod((T2.C700020016-T2.C700020015),60*60*24)/60/60,0)) || '小时' || decode(trunc(mod((T2.C700020016-T2.C700020015),60*60)/60,0),0,'00',trunc(mod((T2.C700020016-T2.C700020015),60*60)/60,0)) || '分' from t153 t2
------解决方案--------------------再套个查询就可以了吧
select decode(a........) from (
select t2.*,trunc((T2.C700020016-T2.C700020015)/60/60/24,0) a,trunc(mod((T2.C700020016 - T2.C700020015), 60 * 60) / 60, 0) b from (
from t153 t2) )
------解决方案--------------------WITH r AS
(SELECT (1343873132 - 1343706107) x FROM dual)
SELECT lpad(trunc(x / 60 / 60 / 24), 2,0)
------解决方案-------------------- '天'
------解决方案--------------------
lpad(trunc(MOD(x, 60 * 60 * 24) / 60 / 60), 2,0)
------解决方案-------------------- '小时'
------解决方案--------------------
lpad(trunc(MOD(x, 60 * 60) / 60), 2,0)
------解决方案-------------------- '分'
FROM r