-2
我要實現這個梅託德java的查詢保存在一個列表<String>持久JPQL
public List<String> getAuthorArticlesPercentageForCategory (String categoryText) {
/* in this query i count the articles in a spesific category*/
Query q=em.createQuery("SELECT COUNT(ar) FROM Article ar WHERE ar.categoryId.categoryText=:categoryText")
.setParameter("categoryText", categoryText);
Long n=(Long)q.getSingleResult();
/* in this query i found the authors and count the articles which they wrote in the spesific category */
Query w=em.createQuery("SELECT ar.authorId.firstName,count(ar) FROM Article ar WHERE ar.categoryId.categoryText=:categoryText GROUP BY ar.authorId");
w.setParameter("categoryText", categoryText);
List list1=w.getResultList();
/*stop here i cant go on*/
return list;
此列表必須以這種格式返回List<String>
:
名稱:(ar.authorId.firstName) ,類別(類別名稱),百分比(這必須從2query/n開始計數(ar))
那麼在獲得「n」時有什麼意義? –
n來自第一個查詢。這是來自特定類別的計數(文章)。我想查找每位作者發佈的文章的百分比 – palios7