o********s 发帖数: 971 | 1 I have a table called customers (id(primary key), customer name, purchase
date, and receipt number(foreign key))
and
another table called purchases (receipt number(primary key), details, amount
)
the mapping is done correctly (many to one) and all the other easy hql runs
just fine
I want to find out the most recent purchases for each customer with the
amount shown. So, basically, the result is a list of unique customers,
sorted by purchase date, and grouped by customers name, with the purchase
a | m******t 发帖数: 2416 | 2
The Criteria API might be helpful.
Your table relationship looks a little peculious though. Maybe I don't
really understand your application logic, but shouldn't it be a receipt
referencing its customer id, instead of the other way around?
【在 o********s 的大作中提到】 : I have a table called customers (id(primary key), customer name, purchase : date, and receipt number(foreign key)) : and : another table called purchases (receipt number(primary key), details, amount : ) : the mapping is done correctly (many to one) and all the other easy hql runs : just fine : I want to find out the most recent purchases for each customer with the : amount shown. So, basically, the result is a list of unique customers, : sorted by purchase date, and grouped by customers name, with the purchase
| f*******4 发帖数: 345 | 3 Try this:
select c.customerName, c.purchaseDate, p.amount from Customer c left join c.
purchases as p group by c.customerName order by c.purchaseDate desc |
|