-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Projection and subquery
PostPosted: Fri Feb 25, 2011 6:24 am 
Newbie

Joined: Fri Feb 25, 2011 6:13 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.