2016-07-04 78 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因爲你還沒有它的別名是...導致你的問題。一旦你別名了,它就會抱怨它需要的任何其他缺失的組。

另外指標列不需要在組中,因爲它是一個靜態值。

而且最重要的是,您應該隨時在您使用的列的任何位置別名,以避免混淆。這只是一個很好的做法。