2016-07-04 77 views
0

我发现了很多类似的问题,基本上我需要把所有不被函数聚合的列放到组中。然而,这似乎并不奏效。不是一组声明

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

“GROUP BY”中的'indicator'列? – Mchl

+1

似乎不工作是非常含糊的!什么特别是不工作的语法?预期的聚合结果?包括一些样本数据以及基于该数据的样本预期结果将是很好的。 – Matt

+0

有或没​​有指示符时,它不是按表达式分组,而是从分组中的选择中缺少语句。 – Elsendion

回答

1

你有两个不同的number执行列(用于stmt)在你的每个表中使用一个作为UC和UD的别名。

让你按需求有这2列中明确列出的是这样的:

group by UC.numberExecutions , UD.NUMBEREXECUTIONS , other columns 

当前已BY子句只包括其中的一个组numberExecutions因为你还没有它的别名是...导致你的问题。一旦你别名了,它就会抱怨它需要的任何其他缺失的组。

另外指标列不需要在组中,因为它是一个静态值。

而且最重要的是,您应该随时在您使用的列的任何位置别名,以避免混淆。这只是一个很好的做法。