请任何人帮我转换为HQL吗?
SELECT COUNT(customerId) AS `cnt`
FROM property
GROUP BY customerId
ORDER BY `cnt`
DESC LIMIT 1
答案 0 :(得分:2)
您的SQL查询:
SELECT COUNT(customerId) AS `cnt`
FROM property GROUP BY customerId ORDER BY `cnt` DESC LIMIT 1
可以在HQL中以相同的方式编写。
重要的是:你如何映射POJO。
所以我想你有一个类属性,你有一个属性customerId。
所以你的查询可能是:
SELECT COUNT(P.customerId) AS `cnt`
FROM Property P
GROUP BY P.customerId
ORDER BY `cnt` DESC LIMIT 1
最后,我建议您以这种方式重写SQL查询以获取MAX值:
SELECT MAX(t.cnt)
FROM
(SELECT COUNT(customerId) as cnt
FROM property) t