在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 (支持)