我正在注入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
最后一列应为每个姓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
我发现问题出在group by
。我的目标就像是第一张桌子,但对于每个姓氏,我都想要它的总和。怎么弄这个?