avatar
急问hibernater query# Java - 爪哇娇娃
o*s
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
avatar
m*t
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

avatar
f*4
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
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。