0
即时寻找在这个有点帮助,我是一个有点迷糊命名查询摸出平均
我创建了存储标记为用户
基本上我想创建一个命名查询到实体使用和一个自动工作了平均水平,唯一的问题是我只想要一个选择的列进行平均
目前该表是:
@Entity(name = "MARKING")
public class Marking implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private Person marker;
@ManyToOne
private Project project;
private String markingCompleted, markSectionOne, markSectionTwo, markSectionThree, markSectionFour,
markSectionFive, markSectionSix, markSectionSeven, markSectionEight,
markSectionNine, markSectionTen, markSectionEleven, markSectionTwelve, markSectionThirteen, markAdjust, overalMark, thirdMarker, plagorism;
什么,我为我王,是我应该如何组织查询,只会制定出平均markingSectionOne - 十三
谢谢你们
编辑
我已经加入到这个我的门面,但它似乎不正确的是它呢?
public TypedQuery<Double> markingAvg(Project id) {
System.out.println("id = " + id);
TypedQuery<Double> query = em.createQuery("select ((m.markSectionOne + m.markSectionTwo + m.markSectionThree + "
+ "m.markSectionFour + m.markSectionFive + m.markSectionSix + m.markSectionSeven +"
+ "m.markSectionEight + m.markSectionNine + m.markSectionTen + m.markSectionEleven +"
+ "m.markSectionTwelve + m.markSectionThirteen)/13.0) from Marking m where m.project = :id", Double.class);
query.setParameter("id", id);
double avg = query.getSingleResult();
return null;
}
莫非你检查编辑我对我的问题是这样吗? – user2061913
它看起来像你想'GROUP BY'项目。 – MGorgon