我想计算减去后的总和,请帮帮我
SELECT t1.*
FROM table1 t1
MINUS
SELECT t2.*
FROM table2 t1
JOIN customers c ON t1.number = t2.number;
答案 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;
您有两个表(您的问题中的 table1
和 table2
)具有完全相同的列,这似乎很奇怪。
此外,这还做了一些有用的事情,即计算 number
中非客户的 table1
数量。