我试图在java中创建一个sql语句,它使用timediff函数比较表中的两个sql日期对象。这就是我的陈述:
SELECT EMPLOYEEID, COUNT(ORDER_TYPE) AS BREAKFASTCOUNT, MIN(TIMEDIFF(ORDER_ACCEPTED_TIME,ORDER_COMPLETION_TIME)) AS MINPREP, MAX(TIMEDIFF(ORDER_ACCEPTED_TIME, ORDER_COMPLETION_TIME)) AS MAXPREP FROM ORDERS WHERE ORDERDATE BETWEEN '4/01/2015' AND '4/30/2015' AND ORDER_TYPE ='Breakfast' GROUP BY EMPLOYEEID
但是,当我运行此语句时,我收到错误:
java.sql.SQLSyntaxErrorException: 'TIMEDIFF' is not recognized as a function or procedure.
是否有任何理由发生此错误?
答案 0 :(得分:0)
我希望,这是您正在寻找的查询。这显示了以分钟为单位的时差。
SELECT
EMPLOYEEID,
COUNT(ORDER_TYPE) AS BREAKFASTCOUNT,
MIN(dateDIFF(MINUTE,ORDER_ACCEPTED_TIME,ORDER_COMPLETION_TIME)) AS MINPREP,
MAX(dateDIFF(MINUTE,ORDER_ACCEPTED_TIME, ORDER_COMPLETION_TIME)) AS MAXPREP
FROM ORDERS
WHERE ORDERDATE BETWEEN '4/01/2015' AND '4/30/2015'
AND ORDER_TYPE ='Breakfast'
GROUP BY EMPLOYEEID