如何证明表B中存在所有查询A中的所有记录,以获取数百万记录?

发布于 2025-01-28 06:10:38 字数 384 浏览 3 评论 0原文

我编写了查询(在Microsoft SQL Server Management Studio V18中),该工作室进行了多个内部连接,以提供3列的结果:ZipCode,ID,收入。

该结果集包含1.18亿条记录

I具有2列的表B:ZipCode,ID

表B包含1.23亿记录,

表B中存在这些1.18亿记录,我想证明这一点。 我该怎么做?我不希望另一个结果集将所有这1.18亿记录在输出控制台上显示。

我可以在临时表中添加第一个结果设置,但是在那之后我被卡住了。 理想情况下,我希望看到在控制台上打印的东西,这些内容将说“临时表中的所有记录都存在于target表中< table_name>''

如果没有,什么可以证明所有这些记录都存在于目标表中的理想方式?

I have query written (in Microsoft SQL Server Management Studio V18) which does multiple inner joins to give result set with 3 columns: ZipCode, ID, Income.

This result set contains 118 Million records

I have Table B with 2 columns: ZipCode, ID

Table B contains 123 Million records

These 118M records are present in Table B and I want to prove that.
How do I do this? I don't want another resultset that will display all these 118M records on the output console.

I can add first result set in a temp table but I am stuck after that.
Ideally I would like to see something printed on the console that will say that "All the records from temp table are present in target table<Table_Name>"

If not, what could be an ideal way to prove that all these records are present in target table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨光如昨 2025-02-04 06:10:38

因此,在说您将查询结果推到temp表中说#a之后,我们可以按照以下

IF NOT EXISTS
(
SELECT TOP 1 1
FROM #a A
WHERE NOT EXISTS 
(
SELECT 1 FROM TableB B
ON A.ZipCode=B.ZipCode 
AND A.Id= B.ID
)
)

BEGIN
PRINT 'All the records from temp table are present in target table<Table_Name>'
END

so after say you have pushed your query results into temp table say #a, we can proceed like below

IF NOT EXISTS
(
SELECT TOP 1 1
FROM #a A
WHERE NOT EXISTS 
(
SELECT 1 FROM TableB B
ON A.ZipCode=B.ZipCode 
AND A.Id= B.ID
)
)

BEGIN
PRINT 'All the records from temp table are present in target table<Table_Name>'
END
自此以后,行同陌路 2025-02-04 06:10:38
WITH 
TA AS (SELECT ...), --> first query
TB AS (SELECT ...)  --> second query
SELECT * FROM TA
EXCEPT
SELECT * FROM TB
UNION ALL
SELECT * FROM TB
EXCEPT
SELECT * FROM TA;

然后替换您的查询ta和tb。

WITH 
TA AS (SELECT ...), --> first query
TB AS (SELECT ...)  --> second query
SELECT * FROM TA
EXCEPT
SELECT * FROM TB
UNION ALL
SELECT * FROM TB
EXCEPT
SELECT * FROM TA;

Then replace by your queries TA and TB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文