前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >MySQL 8.0不支持GROUP BY ASC DESC

MySQL 8.0不支持GROUP BY ASC DESC

原创
作者头像
云鹏
修改2021-04-30 10:13:24
修改2021-04-30 10:13:24
2.8K00
代码可运行
举报
文章被收录于专栏:MySQL捉虫MySQL捉虫
运行总次数:0
代码可运行

https://dev.mysql.com/worklog/task/?id=8693

根据WL#8693,MySQL 8.0后续版本将不再支持GROUP BY ASC DESC语法.

测试表和数据

代码语言:javascript
代码运行次数:0
运行
复制
create table t (id int primary key,name varchar(20));
insert into t values(1,'test'),(2,'test2');

MySQL 5.7.30

代码语言:javascript
代码运行次数:0
运行
复制
mysql> select id,count(*) from t group by id desc;
+----+----------+
| id | count(*) |
+----+----------+
| 2 | 1 |
| 1 | 1 |
+----+----------+
mysql> show warnings;
+---------+------+----------------------------------------------------------------------+
| Level  | Code | Message  |
+---------+------+----------------------------------------------------------------------+
| Warning | 1287 | 'GROUP BY with ASC/DESC' is deprecated and will be removed in a 
future release. Please use GROUP BY ... ORDER BY ... ASC/DESC instead |
+---------+------+----------------------------------------------------------------------+
1 row in set (0.00 sec)

MySQL 8.0.22

代码语言:javascript
代码运行次数:0
运行
复制
mysql> select id,count(*) from t group by id desc;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL 
server version for the right syntax to use near 'desc' at line 1

该WL还会影响升级操作

在MySQL 5.7创建测试表和存储过程

代码语言:javascript
代码运行次数:0
运行
复制
create database test;
use test;
create table t (id int primary key,name varchar(20));
insert into t values(1,'test'),(2,'test2');
delimiter $
create procedure test_group()
begin
 select id,count(*) from t group by id desc;
end $
delimiter ;

关闭实例后,使用MySQL 8.0.22程序进行升级

代码语言:javascript
代码运行次数:0
运行
复制
/data/mysql8_debug/bin/mysqld_safe --defaults-file=./my.cnf --upgrade=FORCE &

升级失败

代码语言:javascript
代码运行次数:0
运行
复制
[ERROR] [MY-013235] [Server] Error in parsing Routine 'test'.'test_group' 
during upgrade. You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL 
server version for the right syntax to use near 'desc; end' at line 3
[ERROR] [MY-010022] [Server] Failed to Populate DD tables.
[ERROR] [MY-010119] [Server] Aborting
[System] [MY-010910] [Server] /data/mysql8_debug/bin/mysqld: 
Shutdown complete (mysqld 8.0.22-debug) Source distribution.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档