简体   繁体   English

在两个sql表之间查找更改的数据

[英]To find changed data between two sql tables

I have an issue in finding the changes between to tables. 我在查找表之间的更改时遇到问题。

I have a 2 discount files which i have uploaded to sql database using aws redshift. 我有2个折扣文件,已使用AWS Redshift上传到sql数据库。

I have to find the changes in both the tables. 我必须在两个表中都找到更改。 Which discount are changed for next month. 下个月将更改哪些折扣。

I have prepared the query but it brings all the columns from previous month as well. 我已经准备好查询,但是它也带来了上个月的所有列。

My requirement is only changed data 我的要求是仅更改数据

I have created below query 我在下面创建了查询

(select * from imtest.aws_discount_new
minus
select * from imtest.aws_discount_prev)
UNION
(select * from imtest.aws_discount_prev
minus
select * from imtest.aws_discount_new);

But in this data from imtest.aws_discount_prev table which is not present in imtest.aws_discount_new are also included . 但是在imtest.aws_discount_prev表中的数据中,也包括了imtest.aws_discount_new中没有的数据。 which needs to be excluded 需要排除

(select * from imtest.aws_discount_new
minus
select * from imtest.aws_discount_prev)
UNION
(select * from imtest.aws_discount_prev
minus
select * from imtest.aws_discount_new);

Expected : only new data from new file and data changed data prev file. 预期:仅来自新文件的新数据和已更改数据的前一文件。

I think you only need the first part of your query: 我认为您只需要查询的第一部分:

select * from imtest.aws_discount_new
minus
select * from imtest.aws_discount_prev

This should get "new" records, which are not in "prev". 这应该获得“新”记录,这些记录不在“上一条”中。 That seems like a reasonable interpretation of what you want. 这似乎是您想要的合理解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM