开发者

HQL query to filter date from datetime data

I want to convert datetime format to string format in HQL count. For example开发者_开发百科, I have redundant attendance data in each day of month of multiple employee which I need to count and get distinct data for a single day.

select Count(distinct att.AttDate) from AttendanceTable att where att.AttDate between '" + startDate.Date + "' and '" + endDate.Date + "'

but this query counting each and every datetime data because of time value. So I need to convert datetime into string.


HQL allows only certain set of functions.

Try

select count(distinct (
    day(att.AttDate) + 
    31 * month(att.AttDate) + 
    366 * year(att.AttDate) ))

You could try str() or cast() but the result won't be consistent over different databases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜