2

I have the following query

select sum(r.score)/count(r) from Rating as r
    group by r.item
    order by sum(r.score)/count(r) desc

My problem is that hibernate rounds the result sum(r.score)/count(r).

How can I force Hibernate to return the float value of the result?

4

2 に答える 2

3

平均を見つけることだけを気にする場合は、常に a を返すavg()Double集計関数を使用できます。

select avg(r.score) from Rating as r
    group by r.item
    order by avg(r.score) desc
于 2013-08-26T17:13:41.143 に答える
1

avgこの状況に最適です。double に変換する一般的なケースでは、CAST を使用できます。

select sum(r.score) / (CAST (count(r) AS DOUBLE PRECISION)) from Rating as r
    group by r.item
    order by sum(r.score) / (CAST (count(r) AS DOUBLE PRECISION)) desc
于 2013-08-26T17:26:12.313 に答える