-->
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.  [ 3 posts ] 
Author Message
 Post subject: Distinct Count across multiple columns
PostPosted: Mon Aug 01, 2011 10:14 am 
Beginner
Beginner

Joined: Fri Nov 13, 2009 4:05 pm
Posts: 30
I have been searching for the last few days for a solution to a COUNT DISTINCT problem but I have yet to find a resolution. In a reporting application, I need to perform an aggregation SQL statement as follows:

Code:
SELECT tbl.salesRep as X,
            COUNT(DISTINCT tbl.item, tbl.vendor) as Y
   FROM mySalestable tbl
WHERE facilityId in (:facilityIds)
GROUP BY tbl.salesRep


When using HQL I get the following error:
org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found ',' near line 1, column 61

Is this not possible? Can someone show me how to do this with either HQL or Criteria API?


Top
 Profile  
 
 Post subject: Re: Distinct Count across multiple columns
PostPosted: Mon Jul 29, 2013 7:16 am 
Newbie

Joined: Mon Jul 29, 2013 7:14 am
Posts: 1
Did you ever find a solution on this issue?


Top
 Profile  
 
 Post subject: Re: Distinct Count across multiple columns
PostPosted: Tue Jul 30, 2013 8:03 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
Here is a solutions for simple query using criteria :

Integer itemCount = (Integer) session.createCriteria(Student.class).
setProjection(Projections.countDistinct("item"))
.uniqueResult();

In this way you can get the distinct results , but if you want for a complex query, this can not be done using HQL

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.