MyBatis-Plus和shardingsphere一起用。子查询取别名读取不到的问题。

https://github.com/baomidou/mybatis-plus/issues/2585

在使用MP和Shardingsphere的某些版本中,可能会出现join 子查询表 取别名之后,在where中用这个别名报错  Can not find owner from table.

复制代码
// 重点是外层SQL不要出现 * ,不要使用别名,需要的字段都写清楚(内外层sql都要写清楚),才可以查出数据,不然要么是数据为空,要么是报错 Can not find owner from table.

// 正常工作
select resId,resType from (
        select id as resId, type as resType from test
) res where resId > 0 GROUP BY resType

// 没有数据
select * from (
        select id as resId, type as resType from test
) res where resId > 0 GROUP BY resType

// 没有数据
select * from (
        select * from test
)res where id > 0 GROUP BY res.type

// IllegalStateException : Can not find owner from table.
select * from (
        select * from test
) res where res.id > 0 GROUP BY res.type
复制代码

 不用别名.字段,也不给字段取别名,倒是解决了。问题是如果还有其他子查询也是查了个any_value(create_time) 列名就重复了。没有深追这个issue。不知道最新版本修复没

posted @   长寿奉孝  阅读(1182)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示