我发现了很多类似的问题,基本上我需要将所有未被函数聚合的列放在组中。然而,这似乎不起作用。
select UC.executionTime as executionTime,
UC.aggregationTime as aggregationTime,
UC.totalTime as totalTime,
case when UC.numberExecutions <= UD.NUMBEREXECUTIONS then UC.numberExecutions
else UD.NUMBEREXECUTIONS
end as numberExecutions,
(avg(UD.AVERAGETIME)*(count(UD.AVERAGETIME))+avg(UC.executionTime))/((count(UD.AVERAGETIME))+1.0) as averageTime,
UC.layer as layer,
UC.domain as domain,
UC.name as name,
UC.componentType as componentType,
UC.operation as operation,
UC.version as version,
"UseRateDay" as indicator
from UCtable as UC, USE_RATE_DAY as UD
where UC.name=UD.NAME and UC.layer=UD.LAYER
and UC.domain=UD.DOMAIN and UC.componentType=UD.COMPONENTTYPE
and UC.operation=UD.OPERATION AND UC.version=UD.VERSION and UC.indicator="UseRateDay" and (floor(UC.executionTime/(24*60*60*1000))*(24*60*60*1000) <= UD.EXECUTIONTIME and (ceil(UC.executionTime/(24*60*60*1000)) * (24*60*60*1000))*2 > UD.EXECUTIONTIME)
group by executionTime, aggregationTime,totalTime, numberExecutions,layer, domain, componentType, name, operation, version
我在哪里错过了?
答案 0 :(得分:1)
您有两个不同的 numberExecutions 列(在案例stmt中使用),每个表中有一个别名为UC和UD。
所以你的小组需要明确列出这两个列:
group by UC.numberExecutions , UD.NUMBEREXECUTIONS , other columns
您目前只包含其中一个numberOecutions in group by子句,因为您没有别名...导致您出现问题。一旦你使用别名,它就会抱怨它所需要的任何其他缺失列。
此外,组中不需要指标列,因为它是静态值。
最重要的是,除了使用它们之外,您应该始终为列添加别名以避免混淆。这只是一个很好的做法。