本来想要效果是有多少个userId,结果却显示的是,去重后每组userId有多少个。
select count(id) from ls_wweb_log_call where userId is not null and companyUserId=:companyUserId and createDate BETWEEN :nowDate AND :nextDate group by userId
后来使用如下方式解决:
select count(id) from (select id from ls_wweb_log_call where userId is not null and companyUserId=:companyUserId and createDate BETWEEN :nowDate AND :nextDate group by userId) temp
达到想要的效果,注意,这里在hibernate中需要使用createSQLQuery,然后query.uniqueResult()返回的也不是Long而是java.math.BigInteger,如需要转long,直接用longValue()即可。