我正在DB2中执行以下查询
select SOURCE1 , PLANT1, max(BEGIN_TIMESTAMP) as dat , END_TIMESTAMP,
TIMESTAMPDIFF(2,CAST((END_TIMESTAMP - BEGIN_TIMESTAMP) AS CHAR(22)))
from tab1
group by dat
但是我收到了这个错误:
2:01:01 [SELECT - 0行,0.000秒] [错误代码: - 206,SQL状态:42703] DB2 SQL错误:SQLCODE = -206,SQLSTATE = 42703,SQLERRMC = DAT,DRIVER = 3.50.152 ...执行1条语句,0行受影响,执行/获取时间:0.000 / 0.000秒[0成功,0警告,1错误]
任何想法请
答案 0 :(得分:0)
您需要在GROUP BY
中包含所有非聚合列。目前还不清楚你想要什么,但这应该至少解析并运行:
select SOURCE1, PLANT1, max(BEGIN_TIMESTAMP) as dat , END_TIMESTAMP,
TIMESTAMPDIFF(2, CAST((END_TIMESTAMP - BEGIN_TIMESTAMP) AS CHAR(22)))
from tab1
group by SOURCE1, PLANT1, END_TIMESTAMP;