SQL执行报错

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。

  • 【TiDB 版本】:tidb v3.0.8
  • 【问题描述】:

这个语句不支持?

select game_type_id, sum(count) as count from `member_bet_per_days` where `type` = 9 and `report_date` between 2020-01-06 and 2020-01-12 group by `game_type_id` order by `count` asc limit 5

还是要改成这种?

select game_type_id, sum(count) as count from `member_bet_per_days` where `type` = 9 and `report_date` between 2020-01-06 and 2020-01-12 group by `game_type_id` order by sum(count) asc limit 5

这里和 MySQL 有一些差别,详情请看一下官方文档,关于 ONLY_FULL_GROUP_BY

https://pingcap.com/docs-cn/stable/reference/mysql-compatibility/#sql-模式

排序不支持别名是吧?

我试过了是因为别名count与字段count名字相同导致的,mariadb是支持相同名字的,改成如下别名totalCount是可以跑的

select game_type_id, sum(count) as totalCount from `member_bet_per_days` where `type` = 9 and `report_date` between 2020-01-06 and 2020-01-12 group by `game_type_id` order by `totalCount` asc limit 5

如果问题已经解决,新问题可以创建新的 issue。

好的 谢谢

:+1:

https://github.com/pingcap/tidb/issues/14394

建议 Gtihub issue 不要这样提,这样研发同学可看不懂。你可以试试用英文在 TiDB 的 Github 按照提问的引导来提问。

英文菜:joy:

:joy:

此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。