由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 急问hibernater query
相关主题
Hibernate queryjava架构问题
javax.tools packageHelp! interface Scanner with Pdf file
Java API for XML?Custom Tag: embedding tag inside tag?
java的源程序值得看看Re: Custom Tag: embedding tag inside tag
Sort TreeMap by value?anybody use jfreechart package?
听说HBase很难用A question about JavaScript (转载)
这个闭包怎么写?Made my first Ajax app integrated to Spring.
JPA Criteria API select questionwhat's the deal with my google (转载)
相关话题的讨论汇总
话题: hibernater话题: customer话题: customers话题: query话题: key
进入Java版参与讨论
1 (共1页)
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
1 (共1页)
进入Java版参与讨论
相关主题
what's the deal with my google (转载)Sort TreeMap by value?
swing的text组件能实现ultraedit的列编辑功能吗听说HBase很难用
JTable太弱了,应当改写这个闭包怎么写?
关于report的问题, 请教牛牛们JPA Criteria API select question
Hibernate queryjava架构问题
javax.tools packageHelp! interface Scanner with Pdf file
Java API for XML?Custom Tag: embedding tag inside tag?
java的源程序值得看看Re: Custom Tag: embedding tag inside tag
相关话题的讨论汇总
话题: hibernater话题: customer话题: customers话题: query话题: key