我试图获取状态等于ACCEPTED的AdmissionForms的数量,但此查询未能这样做。
在存储库中,
SELECT COUNT(IF(status='ACCEPTED',1,NULL)), COUNT(IF(status='PENDING',1,NULL)) FROM admissionforms;
我遇到的异常,
org.hibernate.hql.internal.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 16 [SELECT COUNT(if(status = 'ACCEPTED',1,NULL)) FROM admissionforms]
答案 0 :(得分:0)
为什么不只包含WHERE
子句呢?
SELECT COUNT(*) AS ACCEPTED
FROM admissionforms
WHERE status = 'ACCEPTED';
但是,条件聚合也可以这样做:
SELECT SUM(CASE WHEN status = 'ACCEPTED' THEN 1 ELSE 0 END) AS ACCEPTED
FROM admissionforms;