Bug #78402 GROUP BY with expression fails (should succeed)
Submitted: 11 Sep 2015 2:23 Modified: 11 Sep 2015 4:15
Reporter: Su Dylan Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.6.22 OS:Any
Assigned to: CPU Architecture:Any

[11 Sep 2015 2:23] Su Dylan
Description:

Note:
>>>>>
Yesterday, I reported a bug with the same scenario, in which I mentioned a proper error message should be issued. 
However, today I realize that this sql should succeed, since in the document, it is mentioned that MySQL permits expressions in GROUP By clauses.

Therefore I am re-opening this issue by changing the expected result to be :
SQL "select c1+1 from t1 group by c1+1 having c1+1 " succeeds.

Sorry for the inconvenience in this re-openning! If there is any other way for me to re-open this kind of issue, please kindly let me know.

Quote:
=====
https://dev.mysql.com/doc/refman/5.0/en/group-by-handling.html

MySQL permits expressions in GROUP BY clauses, so the alias is unnecessary:
=====

output:
=======
mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1(c1 int, c2 int);
Query OK, 0 rows affected (0.01 sec)

mysql> select c1+1 from t1 group by c1+1 having c1+1;
ERROR 1054 (42S22): Unknown column 'c1' in 'having clause'

mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.22-log |
+------------+
1 row in set (0.00 sec)

Problem:
========
The SQL should succeed.

How to repeat:
drop table if exists t1;
create table t1(c1 int, c2 int); 
select c1+1 from t1 group by c1+1 having c1+1;

Suggested fix:
SQL "select c1+1 from t1 group by c1+1 having c1+1 " succeeds.
[11 Sep 2015 2:26] Su Dylan
The previous issued bug is:
http://bugs.mysql.com/bug.php?id=78395
[11 Sep 2015 4:15] MySQL Verification Team
Hello Su Dylan,

Please do not submit the same bug more than once. An existing bug report already describes this very problem. We hope you add your comments to the original bug instead.

Thanks,
Umesh