这是我的 table
CREATE TABLE `tabletest`
( `id` bigint(20) NOT NULL ,
`type` int(11) NOT NULL DEFAULT '0' ,
`parent_id` bigint(20) NOT NULL DEFAULT '0' ,
PRIMARY KEY (`id`),
KEY `idx_parent_id_type` (`parent_id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
数据:
type parent_id
101 0
101 4
101 6
101 7
101 9
这是 sql 1:
select count(DISTINCT parent_id) from tabletest where type = 101
结果一:
3
这是 sql 2:
select count(DISTINCT parent_id,type) from tabletest where type = 101
结果2:
5
为什么?因为 key ?
最佳答案
这是一个已知的 MySQL 错误,您可以通过其他引擎(spark sql 或其他)检查它。尝试更改您的 MySQL 版本。参见 this
关于MYSQL 'select count(distinct col)' 结果错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45957246/