在HQL中,我会这样做一个查询:
我想按类别
@objc func imageViewTapped() {
// Image has been tapped
}
和
category{ idcategory ;namecategory}
我尝试了以下内容:
operation {montantdebit , Category}
我犯了错误:
select cat.nameCategory, sum(operation.montantdebit) from Operation operation join operation.category cat group by cat.idCategory
答案 0 :(得分:0)
或者您可以参考下面给出的查询:
查询query = session.createQuery("来自员工");
query = session.createQuery("选择e.name,sum(e.salary), 计数(E)" +"来自员工e,其中e.name喜欢'%i%'分组由e.name");
或者您可以参考以下来源: https://www.journaldev.com/2954/hibernate-query-language-hql-example-tutorial
答案 1 :(得分:0)
您的查询需要解决两件事:
GROUP BY
子句中包含字段nameCategory JOIN
子句,因为Category
对象是封装在Operation
对象中的对象您必须按如下方式编写查询:
SELECT operation.category.nameCategory, sum(operation.montantdebit)
FROM Operation operation
GROUP BY operation.category.idCategory, operation.category.nameCategory