来自给定SQL查询的HQL查询

时间:2012-12-14 11:00:48

标签: hibernate count

我有这样的SQL查询:

SELECT COUNT(count) as ovcount from (SELECT COUNT(id) AS count FROM table WHERE
field1=value1 and field2=value2 GROUP BY something1, something2, something3)
as T WHERE count > 1

该语句在HQL中的表现如何?如果查询在FROM之后包含子查询,则Hibernate不支持“简单方法”。

1 个答案:

答案 0 :(得分:1)

最后我认为你要做的是,如果总数高于1,则只获得COUNT(id)。使用HAVING会得到相同的结果。

SELECT COUNT(id) AS count 
FROM table 
WHERE field1=value1 and field2=value2 
GROUP BY something1, something2, something3
HAVING COUNT(id) > 1