2013-06-25 161 views
0

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. 

我知道的語法是醜陋的,請大家指正。

謝謝

回答

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單個查詢,或一種方式,但兩個查詢就會簡單得多,可能有更好的表現。