Hibernate在单个结果中获得多个计数

时间:2018-10-17 07:44:32

标签: java hibernate jpa oracle-sqldeveloper

我可以从这样的数据库查询以获取字符串列表,但是找不到如何在JPA中编写此查询:

SELECT 
COUNT(CASE WHEN CHOICE = 1 THEN 1 END) AS "option1",
COUNT(CASE WHEN CHOICE = 2 THEN 1 END) AS "option2",
COUNT(CASE WHEN CHOICE = 3 THEN 1 END) AS "option3",
COUNT(CASE WHEN CHOICE = 4 THEN 1 END) AS "option4",
COUNT(CASE WHEN CHOICE = 5 THEN 1 END) AS "option5",
COUNT(CASE WHEN CHOICE = 6 THEN 1 END) AS "option6"
FROM SURVEYANSWER where QUESTIONID = 'q1';

如果我在JPA中这样写,我将不会获得存在0的选择

sql.append("select count(o) from SurveyAnswer o where o.questionId = :questionId group by o.choice ");

有人可以帮我吗?

0 个答案:

没有答案