avatar
急问 hibernate query# Database - 数据库
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
k*e
2
if it's MS SQL, and Customername is unique and no more than 1 purcghase on a
single day for each customer
select C.CustomerName, C.PurchaseDate, P.Amount
FROM Customers C
JOIN Purchases P
ON C.Receipt#=P.Receipt#
JOIN (SELECT CustomerName, Max(PurchaseDate) as MaxPDtae FROM CUSTOMERS
GROUP BY CUstomerName
) C1 ON C.CustomerName=C1.CustomerName AND C.PurchaseDate=C1.MaxPDate

amount
runs

【在 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

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