我试图将以下mysql查询转换为hql。问题是它不断在我的案例陈述中抛出错误任何帮助将不胜感激 - 提前感谢。
mysql query
SELECT emisupport_dev.vm_profile.vmp_name, emisupport_dev.virtual_machine.vm_profile_id
FROM emisupport_dev.virtual_machine
INNER JOIN emisupport_dev.vm_profile
ON emisupport_dev.virtual_machine.vm_profile_id=emisupport_dev.vm_profile.id
GROUP BY emisupport_dev.virtual_machine.vm_profile_id
HAVING COUNT(CASE WHEN retired = 1 THEN 1 END) > 0
AND COUNT(CASE WHEN retired = 0 THEN 1 END) = 0;
My attempted hql query
def hql = VirtualMachine.executeQuery("SELECT vm.vmProfile FROM VirtualMachine vm GROUP BY vm.vmProfile HAVING COUNT(CASE WHEN vm.retired = true THEN 1 END) > 0 AND COUNT(CASE WHEN vm.retired = false THEN 1 END) = 0" )
Stacktrace
Error 2013-08-05 12:30:41,811 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - QuerySyntaxException occurred when processing request: [GET] /Support/vmProfile/list
unexpected token: CASE near line 1, column 86 [SELECT vm.vmProfile FROM com.s.VirtualMachine vm GROUP BY vm.vmProfile HAVING COUNT(CASE WHEN vm.retired = true THEN 1 END) > 0 AND COUNT(CASE WHEN vm.retired = false THEN 1 END) = 0]. Stacktrace follows:
Message: unexpected token: CASE near line 1, column 86 [SELECT vm.vmProfile FROM com.s.VirtualMachine vm GROUP BY vm.vmProfile HAVING COUNT(CASE WHEN vm.retired = true THEN 1 END) > 0 AND COUNT(CASE WHEN vm.retired = false THEN 1 END) = 0]