-->
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: Problem with self join with composite key
PostPosted: Thu Aug 23, 2012 6:29 am 
Newbie

Joined: Thu Aug 23, 2012 6:18 am
Posts: 1
Hi ,

I am stuck in this problem. I have a table in which there is a field called "drvloadcount" which is an integer. I need to retrieve, given two timestamps the min and max drvloadcount within that range and also the (min-1) drvloadcount and max+1 drvloadcount(which obviously would fall beyond the timestamps). I have formed the following sql query for the same


select t1.origdrvsn,t1.drvloadcount,t1.timestamp,t2.drvloadcount as prevloadcount, t2.timestamp as prevtimestamp,
t3.timestamp as "max timestamp", t3.drvloadcount as "max drive loadcount",
t4.timestamp as "post timestamp", t4.drvloadcount as "Post load count" from tickets t1
inner join tickets t2 on t2.origdrvsn= tr.origdrvsn and t2.drvloadcount = t1.drvloadcount-1
inner join tickets t3 on t3.timestamp in (select max(timestamp) from tickets
where origdrvsn='HU10048JKT'
and timestamp>1316857928 and timestamp<1317203532)
inner join tickets t4 on t1.origdrvsn = t4.origdrvsn and t4.drvloadcount=t3.drvloadcount+1
where t1.timestamp in (select min(timestamp) from tickets
where origdrvsn='HU10048JKT'
and timestamp>1316857928 and timestamp<1317203532)




(origdrvsn and drvloadcount together form the primary key for this table.) Is there a way I can write the query using Criteria API.

Thanks
Nimesh


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.