得到了"期待CLOSE,发现' =' "尝试在HQL中使用SUM和HAVING时出现异常

时间:2016-10-15 22:10:32

标签: mysql hql

我在HQL中重写了我的JDBC查询。

对于每项工作,我都有工作流程,每个工作流程都有一些任务。 任务可以是' 0',' 1',' 2'和' 3'并有一个BOOL专栏'已完成'。每个工作流程至少有一个类型的任务。我只需要获取那些工作,其工作流程只有类型为' 0'正在完成。

这是我的JDBC查询:

"SELECT j.*

FROM job j

INNER JOIN workflow w

ON j.id = w.job_id

INNER JOIN task t

ON t.workflow_id = w.id

WHERE j.company_id = ?

GROUP BY j.id

HAVING SUM(t.completed = TRUE AND t.type != 0) = 0"

这是我的HQL查询:

"SELECT j

FROM Job j

JOIN c.workflow w

JOIN task t

WHERE j.company_id = :companyId

GROUP BY j.id

HAVING SUM(t.completed = TRUE AND t.type != 0) = 0"

但是,运行此HQL查询会让我“期待CLOSE,找到' ='" SUM子句的异常。

1 个答案:

答案 0 :(得分:0)

经过几个小时的挣扎,我找到了答案。这是工作查询:

"SELECT DISTINCT j
FROM Job j, Workflow w, Task t
WHERE w.job.id = j.id AND
t.workflow.id = w.id AND
j.company.id = ? AND
(SELECT COUNT(*)
FROM Task t
WHERE t.workflow.id = w.id AND
t.completed = TRUE AND
t.type != 0) = 0"