Subject | RE: [Firebird-Architect] Re: Window functions SQL-2003 |
---|---|
Author | Leyne, Sean |
Post date | 2007-06-19T16:10:37Z |
Alexandre,
I also don't see these statements as equivalent.
order by clause.
Sean
> I retranscript from SQL Cookbook by Anthony Molinaro (Oreilly 2005)and
> 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
> d.JOB_COUNTRY='USA') as running_sumI don't see the window function, in this example.
> from employee e
> where e.JOB_COUNTRY='USA'
> order by 5
I also don't see these statements as equivalent.
> with window functionaggregation
>
> 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
> 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