如何在Spring Data JPA中使用Sum SQL的分组(如mysql中的数据透视表)?
@Query("select new org.raznet.sgs.persistence.modelDto.etudiantNoteDto(
n.etudiant as etudiant,
sum(CASE WHEN n.exam.libelle like :a THEN n.note ELSE 0 END) as one,
sum(CASE WHEN n.exam.libelle like :b THEN n.note ELSE 0 END) as two,
sum(CASE WHEN n.exam.libelle like :c THEN n.note ELSE 0 END) as thr) from Note n where n.matiere = :x group by n.etudiant")
public List<etudiantNoteDto> get(@Param("x")Matiere e,@Param("a")String a,@Param("b")String b,@Param("c")String c);
是否可以运行查询以获取如下输出:
Etudiant exam 1 exam 2 exam 3
------------------------------------
Etudiant1 10 14 2
Etudiant2 13 14 3