tags:

views:

32

answers:

1

I am just trying to simplify a Select statement:

Select (a+b+c)/3 AS V, MIN((a+b+c)/3) as Min, MAX((a+b+c)/3) as Max from ....

Is there a clean way to avoid repeating that formula (a+b+c)/3 in the aggregate functions?

Thanks!

+3  A: 
SELECT 
  Result/3 AS V, 
  MIN(Result/3) as Min, 
  MAX(Result/3) as Max
FROM
(
  SELECT (a+b+c) AS Result from Table
) AS outerTable

OR even

SELECT 
  Result AS V, 
  MIN(Result) as Min, 
  MAX(Result) as Max
FROM
(
  SELECT (a+b+c)/3 AS Result from Table
) AS outerTable
Yves M.
+1 but you could perhaps simplify it even further by doing the division in the inner select.
Lieven