ORACLE SQL获取从2条select语句中检索到的两个值的差 [英] ORACLE SQL get difference of two values retrieved from 2 select statements
本文介绍了ORACLE SQL获取从2条select语句中检索到的两个值的差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有2个非常简单的SELECT语句:
We have 2 very simple SELECT statements:
SELECT value from table where date between DATE1 and DATE2
SELECT value from table where date between DATE3 and DATE4
我们需要一种编写单个SQL语句的方法,该方法将获得从这两个SQL语句返回的值"的差.
We need a way to write a single SQL statement which will get the difference of the "value" that is returned from these two SQL statements.
我们尝试了以下操作,但未成功:
We tried the following but it was not successful:
SELECT value from table where date between DATE1 and DATE2
minus
SELECT value from table where date between DATE3 and DATE4
任何建议都将受到高度赞赏.
Any suggestion is highly appreciated.
推荐答案
未经测试,但应该可以工作:
Untested but should work:
SELECT
(SELECT value from table where date between DATE1 and DATE2) -
(SELECT value from table where date between DATE3 and DATE4)
FROM dual;
假定您保证SELECT value
返回单个值
这篇关于ORACLE SQL获取从2条select语句中检索到的两个值的差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文