求一条很多人关注的hql语句。

MYSQL写法:

select count(*) from (select count(*) from s_role group by status) a

我在hql写法:

select count(*) from (select count(*) from Role as r group by u.status) as c

可是hibernate不认这么写的,请问该如何去写呢,谢谢高人

[code="java"]
// hql
String hql = "SELECT COUNT(*) FROM Role p WHERE p.role主键 IN (SELECT MIN(t.role主键) FROM Role t GROUP BY t.status)";
// 应该和sql select count(*) from (select count(*) from s_role group by status) a 实现的功能是一样的
[/code]

hql中, from的表不能是通过子查询得来的

hibernate是可以调用本地sql方法的

我就是直接调用sql了 :D

[quote]那调用sql的话,是不是就要对不同的数据库写不同的sql语句了呢[/quote]
嗯, 那也是没办法的, hql没法实现, 只能折中了

不知道到底要干什么

直接用sql语句写好了,不要那么死~~~灵活一点