Subject | Re: [Firebird-Architect] Improving CTE with ANSI SQL2003 Window Functions |
---|---|
Author | Adriano dos Santos Fernandes |
Post date | 2008-04-08T16:27:23Z |
Philippe Makowski escreveu:
named window.
I'm not certainly, but I think it's more or less this:
WITH OrdersRN AS
(
SELECT EmployeeID, Value,
ROW_NUMBER() OVER(X) AS RowNum,
COUNT(*) OVER(Y) AS Cnt
FROM VOrders
WINDOW X AS (PARTITION BY EmployeeID ORDER BY Value),
Y AS (PARTITION BY EmployeeID)
)
SELECT EmployeeID, AVG(Value) AS Median
FROM OrdersRN
WHERE RowNum IN((Cnt + 1) / 2, (Cnt + 2) / 2)
GROUP BY EmployeeID;
But one window could reference others and then things become more complex.
--
Adriano dos Santos Fernandes
http://www.firebirdsql.org
> Adriano dos Santos Fernandes [08-04-08 19.46] :In the tracker link, there is window_name. That's how you reference a
>
>> What I don't understand and never see is the named "window definition",
>> that starts with the word WINDOW.
>>
>>
> I don't see the word WINDOW in the definition
> cf http://tracker.firebirdsql.org/browse/CORE-1688
> and http://en.wikipedia.org/wiki/Select_(SQL)
> and
> http://wwwdvs.informatik.uni-kl.de/courses/NEDM/WS0607/Vorlesungsunterlagen/NEDM.Chapter.06.Windows_and_Query_Functions_in_SQL.pdf
named window.
I'm not certainly, but I think it's more or less this:
WITH OrdersRN AS
(
SELECT EmployeeID, Value,
ROW_NUMBER() OVER(X) AS RowNum,
COUNT(*) OVER(Y) AS Cnt
FROM VOrders
WINDOW X AS (PARTITION BY EmployeeID ORDER BY Value),
Y AS (PARTITION BY EmployeeID)
)
SELECT EmployeeID, AVG(Value) AS Median
FROM OrdersRN
WHERE RowNum IN((Cnt + 1) / 2, (Cnt + 2) / 2)
GROUP BY EmployeeID;
But one window could reference others and then things become more complex.
--
Adriano dos Santos Fernandes
http://www.firebirdsql.org