1

我有这个查询(在 mySQL cmdline 中运行良好),但是当我使用 executeQuery 在 grails 中运行它时,我收到了这个错误:时间格式错误

这是我的 grails 查询:

def aveTimeToClose = OstFacTicket.executeQuery
("SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(TIMEDIFF(t.closed, t.created)))) as cl " +
"from OstFacTicket t WHERE t.created >= :sdate AND t.created <= :edate AND " +
"t.closed IS NOT NULL", [sdate:start, edate: end])

堆栈跟踪错误是:

 Error 2012-05-17 00:09:44,356 [http-bio-8080-exec-9] 
ERROR util.JDBCExceptionReporter
- Bad format for Time '187:22:05' in column 1
| Error 2012-05-17 00:09:44,365 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  

在 mySQL cmdline 上运行可以正常工作:

mysql> SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(TIMEDIFF(t.closed, t.created)))) as cl
from ost_fac_ticket t where created > '2011-01-01 08:12:49' AND created < 
'2011-12-31 10:12:49';
+-----------+
| cl        |
+-----------+
| 187:22:05 |
+-----------+

谢谢,我很感激任何帮助。

4

1 回答 1

1

我最终遵循mu is too short的建议,只需以秒为单位获取查询结果并使用 groovy 将秒数转换为我想要的格式。

基本上 -

def aveTimeToClose = OstFacTicket.executeQuery("SELECT AVG(TIME_TO_SEC(TIMEDIFF(t.closed, t.created))) as cl "+
        "from OstFacTicket t WHERE t.created >= :sdate AND t.created <= :edate AND t.closed IS NOT NULL", [sdate:start, edate: end])

结果 aveTimeToClose 以秒为单位,可以轻松转换为日期时间格式。

于 2012-05-18T04:45:57.577 回答