Вопрос

Here is my example

SQLfiddle.com.

Could anybody explain why AvgQuant is invalid column name?

Also SQLfiddle is great tool, but how do I set rounding settings? For example, rounding is not correct in the following example (just remove where clause)

SELECT [Location]
  ,Avg([Quantity]) over (partition BY LOCATION) AS AvgQuant
  ,[Street]
FROM tblExample;

Regards

Это было полезно?

Решение

It is because WHERE clause executes before projection thus the alias isn't available in this phase. You must use subquery to achieve what you want.

SELECT *
FROM
(
  SELECT [Location]
      ,Avg([Quantity]) over (partition BY LOCATION) AS AvgQuant
      ,[Street]
  FROM tblExample
) A
WHERE AvgQuant between 3.5 and 5.5;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top