-->
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: GROUP BY DATE with a DateTime field
PostPosted: Wed May 07, 2008 4:44 am 
Newbie

Joined: Wed May 07, 2008 4:39 am
Posts: 3
Hi,

I have a table with records that contains a datetime field. I want to retrieve the average number of records per day.

I could do this:

Code:
IList results = session.CreateCriteria(typeof(Cat))
                    .SetProjection(Projections.ProjectionList()
                    .Add(Projections.RowCount(), "AverageRecordsPerDay")
                    .Add(Projections.GroupProperty("RecordDate"), "date")
                )
                .List();


But this will do the grouping on DATE & TIME part of the field and not only the DATE part of the field.

Any idea?

Thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 5:00 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
u can try to map that column once again as Date property with insert,update = false, and using formula=sqlFunctionToConvertDatetime2Date(RecordDate) (use some db function here) and try to use group by on this property


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.