将count()和min()的SQL查询转换为HQL

时间:2015-07-03 12:18:58

标签: sql hql

这是我的SQL查询:

SELECT tab2.Tavolo, MIN(mycount) as num_posti_min  
FROM (
        SELECT tab1.Tavolo, COUNT(tab1.Tavolo) as mycount
        FROM posto as tab1
        WHERE tab1.disponibilita = true  
        GROUP BY tab1.Tavolo
        HAVING COUNT(tab1.Tavolo) >= 1
    ) as tab2;

如何在HQL中转换它?
那我怎么能读出它的结果呢?

1 个答案:

答案 0 :(得分:0)

您可以使用Hibernate属性,而不是像这样编写HQL

session.createSQLQuery(String sqlQuery)

see an example here