为提高效率,请提供以下信息,问题描述清晰能够更快得到解决:
【TiDB 版本】
【问题描述】
select * from table_a where
field1 = ‘a’
and field2 = ‘b’
group by field3;
报错: this is incompatible with sql_mode=only_full_group_byuery
支持的方式有两种:
-
关闭 TIDB 的 SQL 模式 ONLY_FULL_GROUP_BY
-
sql 改造 ,在 group by 前 嵌套一层 select
select * from (
select * from table_a where
field1 = ‘a’
and field2 = ‘b’
)tmp
group by field3;
发现这种 方式可行的原因:
项目内对于group by 的应用场景一般是用于排序后 取 group by 下的分类的最新一条数据。
类似:
select * from (
select * from table_a where
field1 = ‘a’
and field2 = ‘b’
order by create_time desc
)tmp
group by field3;
疑问:
暂时没有明白这种sql 的嵌套可以支持的原理,希望大佬能解惑. 谢谢
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。