Java HQL如何对实体中的列表使用sum函数
大家好,我需要你们的帮助 如何将HQL的Sum函数用于一个实体的列表 我试图通过代码示例来解释我的问题 这是我的发票Java HQL如何对实体中的列表使用sum函数,java,hibernate,hql,Java,Hibernate,Hql,大家好,我需要你们的帮助 如何将HQL的Sum函数用于一个实体的列表 我试图通过代码示例来解释我的问题 这是我的发票 @Entity public class Invoice extends ExtendedBaseEntity { @Column(nullable = true,length = 50) private String invoiceNo; @Column(nullable = true) @JsonFormat(shape = JsonFormat.Shape.STRING
@Entity
public class Invoice extends ExtendedBaseEntity {
@Column(nullable = true,length = 50)
private String invoiceNo;
@Column(nullable = true)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "EET")
private Date invoiceDate;
@Column(nullable = true,precision = 10,scale = 2)
private BigDecimal amount; getters and setters.....
这是我的文件实体。这个实体有一个发票列表
@Entity
public class File extends ExtendedBaseEntity {
@Column(nullable = true, length = 50)
private String name;
@Column(nullable = true, length = 50)
private String surname;
@Column(nullable = true, length = 50)
private String lawyerCode;
@Column(nullable = true, length = 50)
private String sellerCode;
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@JoinColumn(name = "MBSFILE_OID")
private List<Invoice> invoices = new ArrayList<Invoice>(); setters and getters ....
我该如何应对?你能帮我吗?好的,你需要一份
groupby
声明好的,非常感谢我处理了。好的,你需要一份groupby
声明好的,非常感谢我处理了。
SELECT DISTINCT
SUM(invoice.amount) AS totalAmount
FROM file
LEFT JOIN file.invoices AS invoice