-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mutilplying columns in Aggr functions throws error Help PLS.
PostPosted: Tue Jul 19, 2005 10:47 am 
Newbie

Joined: Tue Nov 30, 2004 2:37 pm
Posts: 16
sum(qi.volume * qi.avgCost) this is producing error.

and also modifying this to

sum(nvl(qi.volume,0.00) * nvl(qi.avgCost,0.00)) is producing error

and also modifying the same to ;

sum(nvl(qi.volume,Double.valueOf(0.00)) * nvl(qi.avgCost,Double.valueOf(0.00))) is producing error

assume the group by, joins, and others are okay...

Please help whether this is possible in hibernate or not?

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 5:10 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
In my experience, aggregating something other than a simple column isn't possible in most SQL dialects. I wouldn't really expect it to be available in HQL.

To be sure, see if you you can write a similar SQL query for your database. If so, at a minimum, you could write a native SQL query to handle this. Otherwise, you need to figure out a way to do this without putting the sum() around the multiplication.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 7:34 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
I don't know which database you're using, but I just tested it with MySQL 4.1 and the following is a valid expression:

Code:
SELECT SUM(col1 * col2) FROM table

As eagle79 suggested, first check if your database supports this expression and use a native SQL query.
Maybe someone from the Hibernate team can tell you, if such an expression is supported by HQL. I guess it is not.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 7:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is possible (in HB3 only) if the Hibernate dialect has the SQL functions explicitly registered.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 7:56 pm 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
sven wrote:
I don't know which database you're using


Only the latest in high technology: DB2/390 7 ;)

I think I tried a statement that attempted something like this:

Code:
select sum(field1 + field2 + field3) from...


but our DB isn't the most modern of systems: doesn't even support CASCADE UPDATE.


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

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.