gpt4 book ai didi

mysql - 计算配置单元中分区表中的不匹配行

转载 作者:行者123 更新时间:2023-11-30 21:33:03 35 4
gpt4 key购买 nike

我有一个用例,我必须计算来自分区配置单元表的两个不同分区的不匹配行(不包括匹配记录)。

假设有一个名为 test 的分区表,它在 as_of_date 列上进行了分区。现在为了获得不匹配的行,我尝试了两个选项-1.)选择计数(x.item_id)

(选择合并(test_new.item_id,test_old.item_id)作为 item_id

(select item_id from test where as_of_date = '2019-03-10') test_new
全外连接
(select item_id from test where as_of_date = '2019-03-09') test_old
在 test_new.item_id = test_old.item_id
其中 coalesce(test_new.item_id,0) != coalesce(test_old.item_id,0)) as x;

2.) 我先创建一个 View ,然后查询它创建 View test_diff 作为
选择 coalesce(test_new.item_id, test_old.item_id) 作为 item_id, coalesce(test_new.as_of_date, date_add(test_old.as_of_date, 1)) 作为 as_of_date
来自测试 test_new
全外连接测试test_old
on (test_new.item_id = test_old.item_id and date_sub(test_new.as_of_date, 1) = test_old.as_of_date)
其中 coalesce(test_new.item_id,0) != coalesce(test_old.item_id,0);

然后我正在使用查询select count(distinct item_id) from test_diff where as_of_date = '2019-03-10';

两种情况都返回不同的计数。在第二个选项中,我得到的计数较少。请就计数不同的原因提供任何建议。

最佳答案

假设您在第二个选项中处理了 test_new、test_old 表(使用 as_of_date = '2019-03-10' 过滤)。

第一个选项,您使用的是 select 子句 count(X.item_id),而第二个选项是 count(distinct)。 distinct 可能会减少您在后面的选项中的项目数。

关于mysql - 计算配置单元中分区表中的不匹配行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55265379/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com