MYSQL 'select count(distinct col)' 结果错误?

维克

这是我的桌子

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

结果 1:

3

这是 sql 2:

select count(DISTINCT parent_id,type) from tabletest where type = 101

结果2:

5

为什么?因为关键?

米兰维莱比特

这是一个已知的 MySQL 错误,您可以通过其他引擎(spark sql 或其他引擎)进行检查。尝试更改您的 MySQL 版本。看到这个

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章