HQL / JPA sum()和group by

时间:2017-02-26 13:42:32

标签: java hibernate jpa

我正在注入HQL查询并拥有此表:

select o.customer.surname, o.amount, o.date, sum(o.amount) as a
        from Order as o
        group by o.id
        order by o.customer.surname

enter image description here

最后一列应为每个姓sum(o.amount)

只有在我使用此查询时,它才能为我工作:

select o.customer.surname, o.amount, o.date, sum(o.amount) as a
        from Order as o
        group by o.customer.id
        order by o.customer.surname

enter image description here

我发现问题出在group by。我的目标就像是第一张桌子,但对于每个姓氏,我都想要它的总和。怎么弄这个?

0 个答案:

没有答案