Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Subqueries in from clause
PostPosted: Wed Jul 13, 2011 11:13 pm 
Newbie

Joined: Wed Jul 13, 2011 10:18 pm
Posts: 2
I beleave hiberbate can't make a subquery in from clause.
I can't find an alternative solution to the above code.

Code:
"SELECT MAX(Soma) FROM " +
"(" +
" SELECT d.data,SUM(d.valor) AS Soma" +
" FROM Dados d" +
" JOIN d.idAlimentadorFk a" +
" JOIN a.idConjuntoFk c" +
" GROUP BY d.data,c.idConjuntoPk" +
" ) WHERE tb2.data = :data");


Bellow there is the sql code that works


Code:
SELECT max(soma) from
(SELECT data_dado,sum(valor_dado) as soma
FROM dados INNER JOIN alimentador ON dados.id_alimentador_fk = alimentador.id_alimentador_pk
INNER JOIN conjunto ON  conjunto.id_conjunto_pk = alimentador.id_conjunto_fk
GROUP BY dados.data_dado, conjunto.id_conjunto_pk)tb2 WHERE data_dado = ('2011-01-01');



Anyone has a solution?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.