Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 用于时间戳的JPQL avg函数_Hibernate_Date_Timestamp_Average_Jpql - Fatal编程技术网

Hibernate 用于时间戳的JPQL avg函数

Hibernate 用于时间戳的JPQL avg函数,hibernate,date,timestamp,average,jpql,Hibernate,Date,Timestamp,Average,Jpql,我需要一个JPQL查询,它应该计算两个日期之间的平均天数。 我这样写了这个查询 select avg(ps.begins-ps.ends) from PackStatus ps where ps.status.code = 'serviceExec' and ps.gossrvcDocPackage.serviceId = 'Usl_3641042_RSOC' and ps.begins between :startDate and :endDat

我需要一个JPQL查询,它应该计算两个日期之间的平均天数。 我这样写了这个查询

select avg(ps.begins-ps.ends) from PackStatus ps where ps.status.code = 'serviceExec'
            and ps.gossrvcDocPackage.serviceId = 'Usl_3641042_RSOC'
            and ps.begins between :startDate and :endDate
            and ps.ends between :startDate and :endDate
但是系统抛出异常“org.hibernate.exception.DataException:无法执行查询” 如果我放置一些其他字段,例如avg(ps.id),它可以正常工作。 在数据库中,ps.ends和ps.begins存储为timestapm。 如何计算两个日期之间的平均天数?
谢谢。

找到日期间平均日差的正确方法是

select avg(day(ps.ends)-day(ps.begins)) from PackStatus ps where ps.status.code = 'serviceExec'
        and ps.gossrvcDocPackage.serviceId = 'Usl_3641042_RSOC'
        and ps.begins between :startDate and :endDate
        and ps.ends between :startDate and :endDate
您还可以发现小时、分钟等方面的差异。只需在小时()或其他度量值上替换日()。

平均值(日(ps.ends)-日(ps.Start))是解决我的问题的正确方法吗?