我怎样才能找到不同的这个 sql 2 行

时间:2021-04-21 03:46:35

标签: sql oracle

我想计算减去后的总和,请帮帮我

SELECT t1.*
FROM table1 t1
MINUS
SELECT t2.*
FROM table2 t1 
JOIN customers c ON t1.number = t2.number;

3 个答案:

答案 0 :(得分:1)

另一种方法是使用 CTE

With cte as (SELECT t1.*
FROM table1 t1
MINUS
SELECT t2.*
FROM table2 t1 
JOIN customers c ON t1.number = t2.number)

Select count(*) from cte;

答案 1 :(得分:0)

一种方法是:

select count(*) from (
SELECT *
FROM table1 t1
MINUS
SELECT *
FROM table2 t1 
JOIN customers c ON t1.number = t2.number
) t

答案 2 :(得分:0)

我怀疑你真的想要:

select count(*)
from (select number
      from table1
      minus
      select number
      from customers
     ) t;

您有两个表(您的问题中的 table1table2)具有完全相同的列,这似乎很奇怪。

此外,这还做了一些有用的事情,即计算 number 中非客户的 table1 数量。

相关问题