【发布时间】:2015-02-26 20:04:23
【问题描述】:
我必须实现这个方法
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>,格式如下:
name: (ar.authorId.firstName) , category(categoryname), percent (这必须是 count(ar) from 2query/n)
【问题讨论】:
-
那么得到“n”有什么意义呢?
-
n 来自第一个查询。这是特定类别的计数(文章)。我想查找每个作者发表的文章的百分比