-->
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 using sum with a subquery
PostPosted: Thu Apr 24, 2008 5:08 am 
Newbie

Joined: Thu Apr 24, 2008 4:55 am
Posts: 1
Location: Austria
Hello!

I have a problem with a query of mine. The Situation:

2 Entities, Person and Disease.
Persons have: id, name, set of diseases
Disease have: id, name, duration, and a referenced person.

The Relationship is a 1:n relationship, one person can have multible diseases

What i want to do is the following:

I want (if it's possible in one query) to get the the count of the persons and the total duration of those diseases. Result should read like this "there were 300 people ill and this caused 4902 days of sickness"

the last approach i tried was this:

Code:
Query query1 = session.createQuery("
SELECT count(p), 
    sum(
          SELECT sum(d.duration) FROM p.diseases d
    )
FROM Person p
WHERE p.diseases.size > 0");


The Error i get is a unexpected Token near the "sum(SELECT" part of the query.

Hibernate version is 3.2.5

Thanks for your help, i'm stuck here for nearly two hours now with this single query..

greetings from Austria,
Klaus


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.