Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议getCountSql支持distinct #11

Closed
masankin opened this issue Mar 4, 2020 · 4 comments
Closed

建议getCountSql支持distinct #11

masankin opened this issue Mar 4, 2020 · 4 comments

Comments

@masankin
Copy link

masankin commented Mar 4, 2020

问题说明:
fenix/src/main/java/com/blinkfox/fenix/jpa/FenixJpaQuery.java

this.sqlInfo.getSql().replaceFirst(REGX_SELECT_FROM, SELECT_COUNT);

如果 this.sqlInfo.getSql() 查询为:
select distinct t.id from t_user

会被替换成
select count(*) as count from t_user

这样导致 list 集合数据 和 count 总数不一样

正确替换sql应该为:
select count(distinct t.id) as count from t_user

解决方案:
1.count查询 正则支持识别 distinct:
2.或者提供一个方法/注解属性,类似 countQuery ,能够手动控制是否使用 distinct

目前解决方法是用 countQuery 查询总数

@blinkfox
Copy link
Owner

blinkfox commented Mar 7, 2020

@masankin 后续可以考虑支持,使用解决方案2 较为合适。

@pengten
Copy link
Contributor

pengten commented Aug 12, 2020

@masankin @blinkfox 根据你们的讨论,我试着做了一版:#24

@pengten
Copy link
Contributor

pengten commented Aug 14, 2020

@masankin 请问你们使用的fenix和jpa版本是多少呢?

@blinkfox
Copy link
Owner

blinkfox commented Dec 3, 2020

这个 issue 新版本有了,我就关了哈

@blinkfox blinkfox closed this as completed Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants