I have this two tables:
Table A
ID TYPE SDATE EDATE RATING 1 M 1/1/2010 1/1/2011 A 1 M 1/3/2010 1/4/2011 B 2 A 7/2/2010 1/31/2015 C 3 M 3/1/2011 1/20/2012 B 4 A 3/1/2011 1/20/2012 B 5 M 3/1/2009 3/1/2009 F 6 M 12/31/2006 12/31/9999 A 7 A 1/1/2006 12/31/9999 B
Table B
ID TYPE SDATE EDATE RATING 1 M 1/1/2010 1/1/2011 A 2 A 7/2/2010 1/31/2015 C 2 A 9/2/2010 1/31/2015 C 3 M 3/1/2011 1/20/2012 B 4 A 3/1/2011 1/20/2012 C 6 M 12/31/2006 12/31/2015 A 7 A 2/1/2006 12/31/9999 B 8 M 1/2/2010 1/2/2012
When I perform a table A minus table B, it gets me the next result:
ID TYPE SDATE EDATE RATING 1 M 1/3/2010 1/4/2011 B 4 A 3/1/2011 1/20/2012 B 5 M 3/1/2009 3/1/2009 F 6 M 12/31/2006 12/31/9999 A 7 A 1/1/2006 12/31/9999 B
I have already identified the case where A.id is not in B.id, but how do I check when it is different in some other column?
I'm not allowed to create anything on the schema, so I have to do it through queries.
So far, this is what I have, but it gives me data that is not correct.
with aminusb as
(
select
*
from A
minus
select
*
from B
)
select
diff.*
from
aminusb diff
,B
where
diff.id = B.id
and
diff.start_date = B.start_date
and
diff.end_date = B.end_date
and
diff.rating <> B.rating
Do you know how could I get the different scenarios?
- When everything is equal but, rating.
- When everything is equal but, end date.
- When nothing is equal but, it has the same id.
I need to get a list of the records that fulfill every scenario so people can check it on detail.
Thanks.
with aminusb as ( SELECT * FROM A MINUS SELECT * FROM B ) select diff from aminusb diff,B where diff.id = B.id and diff.start_date = B.start_date and diff.end_date = B.end_date and diff.rating <> B.rating unpivot ( rating_cd for as in ( SELECT DISTINCT (id) FROM A ) )- StrayChild01