【发布时间】:2021-07-02 03:13:33
【问题描述】:
我需要比较 Teradata SQL 中的两个表。
两个表的样本是
表 1
User Date Ind1 Ind2
12 2010-05-23 Y N
12 2010-06-23 Y Y
12 2010-07-23 Y N
23 2010-04-23 N N
23 2010-05-23 N N
23 2010-06-12 Y N
表 2
User Date Ind1 Ind2
12 2010-05-23 Y N
12 2010-06-23 Y Y
12 2010-07-23 N N
24 2010-03-22 N N
23 2010-04-23 N Y
23 2010-05-23 N Y
23 2010-06-12 Y N
在此示例中,Table 1 与 Table 2 不同,因为它没有用户 24,而且 Ind1 和 Ind2 中的某些值已更改。我通常比较 Teradata 之外的数据,因为我不熟悉代码。由于表非常大,我想知道是否有办法直接比较这些表(例如,对用户使用联接;我有兴趣查看Ind1=Y 更多的情况见表 1)。
预期输出:
Table 1 (where Ind1 and Ind2 have at least 1 Y)
User Date Ind1 Ind2
12 2010-05-23 Y N
12 2010-06-23 Y Y
12 2010-07-23 Y N
23 2010-06-12 Y N
表 2
User Date Ind1 Ind2
12 2010-06-23 Y Y /* it differs from Ind2 */
12 2010-07-23 N N /* it differs from both indicators */
24 2010-03-22 N N /* Not included in Table 1 */
23 2010-04-23 N Y /* it differs from Ind2 */
23 2010-05-23 N Y /* it differs from Ind2 */
23 2010-06-12 Y N /* it differs from Ind1 */
【问题讨论】:
-
编辑您的问题并显示您想要的结果。
-
有几种方法可以比较表,具体取决于您基于 EXCEPT [ALL]、NOT EXISTS 或 FULL JOIN 的预期结果。
-
如果你想看看,我开了一个新问题:stackoverflow.com/questions/66969965/…
标签: sql teradata teradata-sql-assistant