| 
					
						 I'm trying to write this in HQL:
 
 select invitemid, sum(onOrder) 
 from (
 	select 
 		invitemid, 
 		jobid, 
 		sum(case when typeid=1 then quantity else 0 end) -
 		sum(case when typeid=2 then quantity else 0 end) -
 		sum(case when typeid=8 then quantity else 0 end) as onOrder
 	from inv_transaction 
 	where typeid in (1,2,8) 
 	group by invitemid, jobid
 ) as jobOnOrder
 where onOrder>0
 group by invitemid
 
 What I essentially want to do, is add up the details on each job (ordered-received-cancelled) and then ignore all those that are negative (sometimes inventory might be received that wasn't ordered) and sum up the rest, to find out how many are on order for a given item.
 
 Via hibernate, it seems to not allow selects in a from(). I've been looking everywhere and asking the Hibernate guru here, to no avail. Is there any way to get around this? 
					
  
						
					 |