[英]Order Comparison in Oracle SQL
I have two tables, t1, t2. 我有两个表,t1,t2。
For instance: t1 is like this: 例如:t1是这样的:
ID Ordinal
1 1
2 2
3 3
4 4
t2 is like this: t2是这样的:
ID Ordinal
1 1
2 3
3 5
4 6
In this scenario, while I do the comparison of the ordinal, I want to return the order as "no Change", because if you look carefully, the actual order of those two tables are not changed. 在这种情况下,当我对序数进行比较时,我想将订单作为“无变化”返回,因为如果仔细观察,这两个表的实际顺序不会改变。
but in a scenario like this: t2 is like this: 但是在这样的场景中:t2是这样的:
ID Ordinal
1 1
2 5
3 3
4 6
I would like to see the result as ID 2 and 3 are changed from T1. 我希望看到结果,因为ID 2和3从T1更改。
Any thoughts? 有什么想法吗?
Thanks! 谢谢!
Try this: 尝试这个:
SELECT T2.ID
FROM (SELECT ID, ROW_NUMBER() OVER (ORDER BY Ordinal) AS rn FROM T1) T1
JOIN (SELECT ID, ROW_NUMBER() OVER (ORDER BY Ordinal) AS rn FROM T2) T2
ON T1.ID = T2.ID
WHERE T1.rn <> T2.rn
Try using the query below: 尝试使用以下查询:
SELECT a.ID, a.Ordinal, b.Ordinal
FROM (
SELECT t1.*, rownum rnm
FROM t1
ORDER BY Ordinal
)a,
(
SELECT t2.*, rownum rnm
FROM t2
ORDER BY Ordinal
)b
WHERE a.ID = b.ID
-- AND a.rnm <> b.rnm //This deosn't work
AND a.Ordinal <> b.Ordinal
Edit: Updated the query to return the required result set 编辑:更新了查询以返回所需的结果集
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.