我不知道JPQL是否支持这样的查询(我正在使用EclipseLink 2.4.1):
select count(product.id if product.pics.count>0) as proWithPic,count(product.id if product.pics.count=0) as proWithoutPic from Product product group by product.brandName.
我知道语法难看,请纠正我。
由于
答案 0 :(得分:1)
我会执行两个查询。
select count(product.id) as proWithPic from Product product where size(product.pics) > 0 group by product.brandName
select count(product.id) as proWithoutPic from Product product where size(product.pics) = 0 group by product.brandName
可能有一种方法可以在SELECT子句或UNION中使用子选择将它们作为单个查询执行,但是两个查询会更简单并且可能表现更好。