我无法使计算列显示平均值。请参阅:
Cast(AVG(COALESCE(mnth1.HandledCalls,0)+COALESCE(mnth2.HandledCalls,0)+COALESCE(mnth3.HandledCalls,0)) as Decimal(8,2)) as Avg_Handled,
如何让这个节目平均显示3列?有时,可能不会填充mnth2和mnth3。我试图将合并的月份除以计算,以防任何给定时间的任何值为空。我收到错误,说选择列表无效。有什么建议吗?
答案 0 :(得分:1)
这样的事情?
cast(
sum(
coalesce(mnth1.HandledCalls, 0) +
coalesce(mnth2.HandledCalls, 0) +
coalesce(mnth3.HandledCalls, 0)
)
as decimal(29, 10)) /
(
count(mnth1.HandledCalls) +
count(mnth2.HandledCalls) +
count(mnth3.HandledCalls)
)
答案 1 :(得分:0)
Cast(
AVG((SELECT COALESCE(mnth1.HandledCalls,0)
UNION ALL SELECT COALESCE(mnth2.HandledCalls,0)
UNION ALL SELECT COALESCE(mnth3.HandledCalls,0) ))
AS Decimal(8,2)) as Avg_Handled
答案 2 :(得分:0)
您是否尝试过以下操作:
SELECT CAST(AVG(ZEROIFNULL(mnth1.HandledCalls)
+ ZEROIFNULL(mnth2.HandledCalls)
+ ZEROIFNULL(mnth3.HandledCalls) as Decimal(8,2)) as Avg_Handled
FROM ....
默认情况下,Teradata中的聚合函数会忽略NULL值。