Subject RE: [Firebird-Architect] Re: Window functions SQL-2003
Author Leyne, Sean
Alexandre,

> I retranscript from SQL Cookbook by Anthony Molinaro (Oreilly 2005)
> To have a running sum in standard sql:
>
> select e.emp_no
> , e.first_name
> , e.last_name
> , e.salary
> , (select sum(salary) from employee d where d.emp_no <= e.emp_no) as
> running_sum
> from employee e
> where e.JOB_COUNTRY='USA'
> order by 5
>
> with window function
>
> select e.emp_no
> , e.first_name
> , e.last_name
> , e.salary
> , (select sum(d.salary) from employee d where d.emp_no <= e.emp_no
and
> d.JOB_COUNTRY='USA') as running_sum
> from employee e
> where e.JOB_COUNTRY='USA'
> order by 5

I don't see the window function, in this example.

I also don't see these statements as equivalent.


> with window function
>
> select e.emp_no
> , e.first_name
> , e.last_name
> , e.salary
> , sum(e.salary) over (order by e.salary, e.emp_no) as running_sum
> from employee e
> where e.JOB_COUNTRY='USA'
> order by 4
>
> the important keyword is OVER : it transforms aggregate functions like
> sum, count, avg as window functions. they permit detail and
aggregation
> in the same query.

While I don't know the syntax, I don't see why "e.salary" is part of the
order by clause.


Sean