比较查询更改。有更好的办法吗
当我编写查询时,我会分步骤进行。有时,在这个过程中我会意识到我犯了一个“错误”,例如最终获得了额外的记录或丢失了记录。因此,我通常会像这样比较两个查询:
(Select blah blah blah ) Mine
Inner join
((Select blah blah blah ) Orig
Where Mine.PK <> Orig.PK
或者如果我正在查找丢失或额外的记录,我将使用左连接并查找空值。
有没有更好的方法来快速找出为什么两个查询返回不同数量的记录?
When I am writing queries, I will do so in steps. Sometimes, in the process I will realize that I've made a "mistake" such as ending up with extra or losing records. So, I will typically compare the two queries like so:
(Select blah blah blah ) Mine
Inner join
((Select blah blah blah ) Orig
Where Mine.PK <> Orig.PK
or if I'm looking for missing or extra records I will use a left join instead and look for nulls.
Is there a better way to quickly figure out why two queries are returning different numbers of records?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您首先需要完全加入。内连接将只显示 Mine 中的记录,而不显示 Orig 中的记录。完整的连接还会向您显示那些在 Orig 中而在 Mine 中缺失的内容。
检查差异的一种快速但肮脏的方法是比较
的结果CHECKSUM_AGG(CHECKSUM(*))
You need a full join to start with. Inner join will show you only the records that are in Mine but not in Orig. A full join will show you also those that are in Orig and missing in Mine.
A quick and dirty way to check for differences is to compare the result of
CHECKSUM_AGG(CHECKSUM(*))