-->
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: Need to count nulls with other values in one select
PostPosted: Fri Apr 23, 2004 1:20 pm 
Newbie

Joined: Fri Apr 23, 2004 11:27 am
Posts: 1
I am using hibernate 2.1 with Oracle 8.1.7. I want to count the various types of values in a column (called status), but one of the values is null. A simple "...count(status) group by status" will not work because the null are not compared and counted. If I run a the following query, I get the expected results:
select count((nvl(status, 1)), status from mytable group by status;

When I put in simple HQL it say undefined alias nvl. Then I tried to use the native SQL with the aliases, hibernate complains that the command is not properly terminated. The query that I have in the code is:

hibSess.createSQLQuery("select count(nvl({st}.status, 1)), " +
"{st}.status from " + sourceRow.getTableName() +
" as {st} group by {st}.status ", "st", obj.getClass());

The query that is generated does not run. The "as" is superflous. When I remove that from the query hibernate says "invalid column name".

I want to do this simple query and I am making it difficult for myself as I am don't seem to be on the right track. Any help will be appreciated.

Thanks!


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.