Hibernate查询语言中的IFNULL等价物? [英] IFNULL equivalent in Hibernate Query Language?

查看:217
本文介绍了Hibernate查询语言中的IFNULL等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个HQL查询来计算一个项目的平均评分。我希望查询在给定项目没有评级时返回0而不是null - 这样我就可以使用我的查询作为子查询。那有可能吗?是否存在与IFNULL或NVL相当的HQL?

解决方案

COALESCE p>

它返回它的第一个非空参数。



示例:

  COALESCE(id_pati,0)

链接维基百科


I'm trying to write an HQL query which will calculate an average rating for an item. I want the query to return 0 instead of null when there are no rating for a given item - so that I can use my query as a subquery. So is it possible? Is there an HQL equivalent of IFNULL or NVL?

解决方案

COALESCE is the official equivalent.

It returns the first non-null of its arguments.

Example:

    COALESCE(id_pati, 0)

Link Wikipedia

这篇关于Hibernate查询语言中的IFNULL等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆