基于对象属性
问题描述:
JPQL总表达我不知道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.
我知道的语法是丑陋的,请大家指正。
谢谢
答
我会执行两个查询。
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单个查询,或一种方式,但两个查询就会简单得多,可能有更好的表现。