0

我不知道 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.

我知道语法很丑,请纠正我。

谢谢

4

1 回答 1

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 中的子选择将它们作为单个查询执行,但是两个查询会更简单并且可能执行得更好。

于 2013-06-26T14:14:11.593 回答