SELECT DATENAME(mm,actualDate) AS [Month],DATENAME(yyyy,actualDate) AS [YEAR],
(
SELECT balance FROM tbl
WHERE actualDate=(SELECT MIN(actualDate) FROM tbl)) AS startingbalance,
(SELECT balance FROM tbl WHERE actualDate=(SELECT MAX(actualDate) FROM tbl)
) AS endingbalance
FROM tbl
GROUP BY DATENAME(mm,actualDate),DATENAME(yyyy,actualDate)
我在db2中运行这个sql命令,但它的工作没有给我一些错误,如(mm)在使用它的上下文中无效?
答案 0 :(得分:0)
在DB2中使用MONTHNAME和YEAR函数。
替换
DATENAME(mm,actualDate)=> MONTHNAME(actualDate)
DATENAME(YYYY,actualDate)=> YEAR(actualDate)