两个 SQL 查询中的值之间的差异
Difference between values in two SQL queries
我在获取来自两个不同 sql 查询的值之间的实际差异时遇到问题。例如:
查询 1:
SELECT x from db1 where date = 'mm-dd-yy'
查询 2:
SELECT x from db1 where date = 'mm1-dd1-yy'
每次查询returns 10 个不同的值。我想要一个查询 returns 两个查询中值之间的实际差异(来自 Q1 的 Value1 - 来自 Q2 的 Value1,对于 value2 类似等等)尝试了 EXCEPT 但这不起作用。有什么建议吗?
试试这样的东西:
Select x-x2 from
(
(SELECT c1,(case when date = 'mm1-dd1-yy' then c11 end)as x2,x from kdue)
)as y
where date = 'mm1-dd1-yy'
如果我理解正确的话,请看下面的方法是否适合你。
select value1_From_QRY1-value1_From_QRY2 from (
select row_cnt,sum(val1) as value1_From_QRY1,sum(va2) as value1_From_QRY2 from
(SELECT ROWNUM as row_cnt,x as val1 ,0 as val2 from db1 where date = 'mm-dd-yy'
union all
SELECT ,ROWNUM ,0,x from db1 where date = 'mm1-dd1-yy')
group by row_cnt)
SELECT A.x1- B.x2 AS Difference FROM
(
(SELECT c, x1 from db1 where date = 'mm-dd-yy') AS A
JOIN
(SELECT c, x2 from db1 where date = 'mm1-dd1-yy') AS B
ON B.c = A.c
ORDER BY A.c, B.c
我在获取来自两个不同 sql 查询的值之间的实际差异时遇到问题。例如:
查询 1:
SELECT x from db1 where date = 'mm-dd-yy'
查询 2:
SELECT x from db1 where date = 'mm1-dd1-yy'
每次查询returns 10 个不同的值。我想要一个查询 returns 两个查询中值之间的实际差异(来自 Q1 的 Value1 - 来自 Q2 的 Value1,对于 value2 类似等等)尝试了 EXCEPT 但这不起作用。有什么建议吗?
试试这样的东西:
Select x-x2 from
(
(SELECT c1,(case when date = 'mm1-dd1-yy' then c11 end)as x2,x from kdue)
)as y
where date = 'mm1-dd1-yy'
如果我理解正确的话,请看下面的方法是否适合你。
select value1_From_QRY1-value1_From_QRY2 from (
select row_cnt,sum(val1) as value1_From_QRY1,sum(va2) as value1_From_QRY2 from
(SELECT ROWNUM as row_cnt,x as val1 ,0 as val2 from db1 where date = 'mm-dd-yy'
union all
SELECT ,ROWNUM ,0,x from db1 where date = 'mm1-dd1-yy')
group by row_cnt)
SELECT A.x1- B.x2 AS Difference FROM
(
(SELECT c, x1 from db1 where date = 'mm-dd-yy') AS A
JOIN
(SELECT c, x2 from db1 where date = 'mm1-dd1-yy') AS B
ON B.c = A.c
ORDER BY A.c, B.c