0

我得到了这样的 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 不支持“简单方法”。

4

1 回答 1

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
于 2012-12-14T15:02:05.317 回答