-->
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: SELECT COUNT(*) FROM (SELECT .... FROM TABLE GROUP BY col)?
PostPosted: Sun Mar 04, 2007 9:59 am 
Newbie

Joined: Mon Feb 26, 2007 9:42 am
Posts: 2
Hallo,

maybe i do not understand the correct usage of Projections: what I would like to do is something like:
Code:
SELECT  count(*)
FROM
        (SELECT this_.ADDRESS_PROVINCE_CODE                 as y0_,
                count(DISTINCT this_.ADDRESS_PROVINCE_CODE) as y1_
        FROM    WMS_SUPPLIER this_
        WHERE   this_.ADDRESS_PROVINCE_CODE like ?
        GROUP BY this_.ADDRESS_PROVINCE_CODE
        )


With the following chunk of code I manage to generate the subquery:

Code:
        Session sess = (Session) si.getServerSession();
       
        Criteria crit = sess.createCriteria(Supplier.class);
     
        crit.add(Expression.like("addressProvince.id.code", "%M%"));
        ProjectionList projections = Projections.projectionList();

        projections.add(Projections.alias(Projections
                .groupProperty("addressProvince.id.code"), "province"));
        projections.add(Projections.alias(Projections
                .countDistinct("addressProvince.id.code"), "tot"));

        crit.setProjection(projections);
       
        List l = crit.list();


I would like to know how many groups there are, so I would like to insert this aggregated query, in a count projection.

Thanks a lot.

Marco


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.