MySQL至Hologres的数据迁移方法及语句、函数的区别 | 您所在的位置:网站首页 › 实时数仓的评判标准 › MySQL至Hologres的数据迁移方法及语句、函数的区别 |
问题原因 MySQL中,使用count(distinct column_1, column_2, ...)做多列去重计算时,如果某列有值为NULL,则该行的DISTINCT结果为NULL,不计入COUNT统计。 Hologres中,使用count(distinct(column_1, column_2, ...))做多列去重计算时,某字段值为NULL不影响计算结果,会计入COUNT统计。 解决方法 如果想要Hologres的计算结果与MySQL保持一致,则需要将Hologres中的查询语句改为count(distinct column_1 || column_2 || ...)。 使用示例 CREATE TABLE count_distinct_test ( a text, b text ); INSERT INTO count_distinct_test VALUES ('a', 'b'), ('a', NULL), (NULL, 'b'), ('a', 'b'); -- Hologres中做count distinct多列计算 SELECT count(distinct(a, b)::text) FROM count_distinct_test; -- 返回结果 count ------- 3 (1 row) -- Hologres中实现与MySQL结果一致的count distinct多列计算 SELECT count(distinct a||b) FROM count_distinct_test; -- 返回结果 count ------- 1 (1 row) |
CopyRight 2018-2019 实验室设备网 版权所有 |