日期:2014-05-17  浏览次数:20617 次

hql 查询问题。
 现在我有一个表,包含年和月两个字段,需要从oralce中查询出最新一年中最新一个月的一条数据。假设映射实体为T,hql语句怎么写呢? 
比如

column  id    year    month
         1    2013       1
         2    2012       1
         3    2013       3
         4    2012       2


我希望得到ID为3的这条数据。求帮助。

------解决方案--------------------
from T order by T.year DESC, T.month DESC

------解决方案--------------------
max(year * 100 + month);
------解决方案--------------------
Query q = session.createQuery("from T order by T.year DESC, T.month DESC ");
q.setMaxResults(1);
T t = (T)q.uniqueResult();
------解决方案--------------------
list.get(0);
------解决方案--------------------
取id为3的数据
from T t where t.id=3