在第4列

时间:2016-09-02 14:48:19

标签: mysql sql database

我有一张有3列的桌子; TimeRetrieval,TimePorcessing和TimeRendering。所有这3列都显示平均值。现在,我想添加这些avg值并将其显示在名为“AvgTotalTime”的第4列中。

我现在的查询是:

Select 
avg(a.TimeRetrieval) as "Retrieval time",
avg(a.TimeProcessing) as "Processing time",
avg(a.TimeRendering) as "Rendering Time",
(avg(a.TimeRetrieval)+avg(a.TimeProcessing)+avg(a.TimeRendering)) AS "AvgTotalTime"
from TimeLog a

我知道添加3列有问题,但无法找出核心语法。

1 个答案:

答案 0 :(得分:2)

试试这个

SELECT [Retrieval time],
       [Processing time],
       [Rendering Time],
       [Retrieval time]+[Processing time]+[Rendering Time] AS "AvgTotalTime"
FROM 
( 
     Select 
     avg(a.TimeRetrieval) as "Retrieval time",
     avg(a.TimeProcessing) as "Processing time",
     avg(a.TimeRendering) as "Rendering Time"
     from TimeLog a
 )M