Nhibernate Hql查询使用 sum 和 case 组合

来源:互联网 发布:刑侦书籍知乎 编辑:程序博客网 时间:2024/05/08 14:35

在Nhibernate HQL查询中,使用sum 和case 组合

查询事例,根据实体Entity 中“otype”字段值,设置查询列‘price’的正负

三种写法:

1. select   sum(case when  otype='A' then price  when otype='B' then -price  end )  from  Entity  (sql中支持,但hql查询时,控制台查询语句缺少 ‘when otype='B' then -price ’,也就是只有otype='A' 的情况)

2.select sum(case when otype='A'  then  price  else -price end ) from Entity  (支持)

3. select sum(case when otype='A'  then  price  else  case when otype='B' then -price end end ) from Entity (支持)

原创粉丝点击