Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result on aggregate function(distinct)+group by #274

Closed
FlyingMao opened this issue Sep 21, 2017 · 0 comments
Closed

Incorrect result on aggregate function(distinct)+group by #274

FlyingMao opened this issue Sep 21, 2017 · 0 comments

Comments

@FlyingMao
Copy link

Prepare data:

mysql> CREATE TABLE sbtest1(`id` int(10) unsigned NOT NULL,`k` int(10) unsigned NOT NULL DEFAULT '0',`c` char(120),`pad` int(11) NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY (`k`));
d) values(19,19,19);
Query OK, 0 rows affected (0.05 sec)

mysql> insert into sbtest1 values(1,1,'id1',1),(2,2,'id2',2),(3,3,'id3',3),(4,4,'id4',4),(5,5,'id5',1),(6,6,'id6',2),(7,7,'id7',3),(8,8,'$id8$',4),(9,9,'test',3),(10,10,'中',3),(11,11,'i_',4),(12,12,'_g',5),(13,13,'y_u',6),(14,14,'20%',14),(15,15,'a_1',15),(16,16,16,-1),(0,0,0,0),(17,17,'new*\n*line',17),(18,18,'a',18);
Query OK, 19 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> insert into sbtest1(id,k,pad) values(19,19,19);
Query OK, 1 row affected (0.01 sec)

dble result:

mysql> select count(distinct id),pad from sbtest1 group by pad;
+----------------------------+-----+
| COUNT(DISTINCT sbtest1.id) | pad |
+----------------------------+-----+
|                          1 |  -1 |
|                          1 |   0 |
|                          1 |   1 |
|                          1 |   2 |
|                          1 |   3 |
|                          1 |   4 |
|                          1 |   5 |
|                          1 |   6 |
|                          1 |  14 |
|                          1 |  15 |
|                          1 |  17 |
|                          1 |  18 |
|                          1 |  19 |
+----------------------------+-----+
13 rows in set (0.01 sec)

mysql result:

mysql> select count(distinct id),pad from sbtest1 group by pad;
+--------------------+-----+
| count(distinct id) | pad |
+--------------------+-----+
|                  1 |  -1 |
|                  1 |   0 |
|                  2 |   1 |
|                  2 |   2 |
|                  4 |   3 |
|                  3 |   4 |
|                  1 |   5 |
|                  1 |   6 |
|                  1 |  14 |
|                  1 |  15 |
|                  1 |  17 |
|                  1 |  18 |
|                  1 |  19 |
+--------------------+-----+
13 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants