hi,
i wish this query
Code:
SELECT avg( s.value )
FROM (
SELECT *
FROM XYZ
WHERE field1=1
AND field2=17
...
ORDER BY timestamp DESC
LIMIT 2
)
using this criretia
Code:
Criteria querySelect = session.createCriteria(XYZ.class);
querySelect.add(Restrictions.eq("field1", new Long(1)));
querySelect.add(Restrictions.eq("field2", new Long(17)));
...
querySelect.addOrder(Order.desc("timestamp"));
querySelect.setProjection(Projections.avg("value"));
querySelect.setMaxResults(2);
List res = querySelect.list();
SQL generate is
Code:
select avg(this_.value) as
from XYZ this_
where this_.fied1=1 and this_.field2=17
order by this_.timestamp desc limit 2
is not the same result.
how to resolve?
thanks in advance