【问题标题】:HQL count statementHQL 计数语句
【发布时间】:2013-11-29 04:09:03
【问题描述】:

我有这样的代码

 (case app.test when 2 then ''  end) as tested

在参考此文档http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#queryhql-aggregation后,我正在尝试计算这个 app.state 的数量。

 count (case app.test when 2 then 'tested'  end) as tested

在此之后我收到类似

的错误
unexpected token: case 

任何想法

但同样的语句在 mysql 中起作用

COUNT(CASE WHEN app.test= 2 THEN "tested" END) 'tested',

【问题讨论】:

  • 我不认为 hql 允许你使用聚合函数计数与 case.. 你可能不得不使用 sql 查询。看this
  • 没有 hql 允许聚合函数。我用过它们

标签: hql aggregate-functions


【解决方案1】:
Select count(app.state) as Confirmed from App app where app.state=2 

【讨论】:

  • 感谢您的努力,但在这里我必须为问题的案例陈述应用计数
【解决方案2】:

我找到了解决办法

sum(case when app.test=2 then 1 else 0 end) as tested

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-02
    • 2023-03-17
    • 2011-10-27
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    相关资源
    最近更新 更多