开发者

hql select from select problem

开发者 https://www.devze.com 2023-03-02 13:35 出处:网络
I would like to count the number of groups of a group by statement. In SQL that would look like: select count(*) from (select count(*) from MyTable t group by t.col1, t.col2) g

I would like to count the number of groups of a group by statement. In SQL that would look like:

select count(*) from (select count(*) from MyTable t group by t.col1, t.col2) g

But in HQL it seems I can not do a select in a select as I did in the previous sql. I guess the problem is that Hibernate does not support subquery in the from clause. Is there 开发者_如何学Goany way to do this in hql?


Well, I have finally run the following query in hql:

select count(*) from MyTable t group by t.col1, t.col2

and then used the size of the returned list, which is exactly the number of groups.

0

精彩评论

暂无评论...
验证码 换一张
取 消