开发者

HQL query to filter date from datetime data

开发者 https://www.devze.com 2023-03-09 05:07 出处:网络
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 d

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

精彩评论

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