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.  [ 2 posts ] 
Author Message
 Post subject: Aggregate Function Query, Mapping, Code Example
PostPosted: Fri May 23, 2008 5:59 am 
Newbie

Joined: Fri May 23, 2008 5:39 am
Posts: 1
The example query criteria code for the aggregate function usage from the nhibernate documentation.
Code:
IList results = session.CreateCriteria(typeof(Cat))
.SetProjection( Projections.ProjectionList()
.Add( Projections.RowCount(), "catCountByColor" )
.Add( Projections.Avg("Weight"), "avgWeight" )
.Add( Projections.Max("Weight"), "maxWeight" )
.Add( Projections.GroupProperty("Color"), "color" )
)
.AddOrder( Order.Desc("catCountByColor") )
.AddOrder( Order.Desc("avgWeight") )
.List();

My question is, Do we need to define the fields avgWeight, maxWeight etc in the mapping and class files?

Any full example code available?

I need to create the query for the following code
Code:
SELECT
   TierId as NETWORK,
   TierTypeId as TIER,
   SUM(ApportionedCallCount) as COUNT,
   SUM(Duration)/60 as MINUTES,
   RateUsed as RATE,
   SUM(RatingElementCost) as CHARGE,
   SUM(RatingElementCost) * 0.05 VAT,
   (SUM(RatingElementCost) + SUM(RatingElementCost) * 0.05) TOTAL
FROM CDR
WHERE CallDate = '14-apr-2008'
   AND CallDirection = 'I'
   AND RatingElementId = 'TRA'
   AND IsDeleted=0
   AND NetworkOperatorId = 'MUL'
   AND Duration > 0
GROUP BY TierId, TierTypeId, RateUsed


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 23, 2008 6:56 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
No, that's just an alias for the calculated column. If you don't specify this alias, one is created for you.

There are examples in the test cases. Have a look at the source distribution.

_________________
--Wolfgang


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