全部, 有一个问题。我有一个在sql server db中运行良好的查询。要在DB2中运行相同的操作,需要完成。
SELECT
EMPID
,TOTALSECONDS /3600 AS Hours
,((TOTALSECONDS % 3600) /60) AS Minutes
,(TOTALSECONDS % 60) AS Seconds
,STATUS
,[DATE]
FROM
(SELECT
SUM(DATEDIFF(ss,STARTDATETIME,ENDDATETIME)) AS TOTALSECONDS,
EMPID,STATUS,
CONVERT(VARCHAR,STARTDATETIME,10) AS [DATE]
FROM <TABLE>
WHERE CONVERT(DATE,STARTDATETIME) = 'xxxx-xx-xx'
GROUP BY EMPID,STATUS,CONVERT(VARCHAR,STARTDATETIME,10)) AS SUMMARY
ORDER BY STATUS,DATE
感谢。
答案 0 :(得分:0)
您的问题是DB2没有DATEDIFF
或CONVERT
函数。有类似的名为TIMESTAMPDIFF
和VARCHAR_FORMAT
。
我认为这个查询将是您想要的,但我不能100%确定我是否已正确地将SQL Server格式转换为DB2格式。 :)
SELECT
EMPID
,TOTALSECONDS /3600 AS Hours
,(MOD(TOTALSECONDS, 3600) /60) AS Minutes
,(MOD(TOTALSECONDS, 60) AS Seconds
,STATUS
,DATE
FROM (
SELECT
SUM(TIMESTAMPDIFF(2, CHAR(ENDDATETIME-STARTDATETIME))) AS TOTALSECONDS
,EMPID
,STATUS
,VARCHAR_FORMAT(STARTDATETIME,'mm-dd-yy') AS DATE
FROM <TABLE>
WHERE VARCHAR_FORMAT(STARTDATETIME,'yyyy-mm-dd') = 'xxxx-xx-xx'
GROUP BY
EMPID
,STATUS
,VARCHAR_FORMAT(STARTDATETIME,'mm-dd-yy')
) A
ORDER BY
STATUS
,DATE