Subject | Re: Window functions SQL-2003 |
---|---|
Author | amoradell |
Post date | 2007-06-19T20:14:55Z |
--- In Firebird-Architect@yahoogroups.com, "Leyne, Sean" <Sean@...>
wrote:
the second query is not a window example !
When I ran the query, I saw a side effect due to currency values
and added a restriction on job_country in the aggregate query.
I never used such syntax.
I think order by e.salary in over clause is here to be consistent
with order by 4.
As far as I know, only Oracle 10g, DB2 9 (and MSSQL partially) have
support for window functions.
You could read examples from
http://www.oreilly.com/catalog/sqlpg2/chapter/index.html
Alexandre
wrote:
>2005)
> Alexandre,
>
> > I retranscript from SQL Cookbook by Anthony Molinaro (Oreilly
> > To have a running sum in standard sql:e.emp_no) as
> >
> > select e.emp_no
> > , e.first_name
> > , e.last_name
> > , e.salary
> > , (select sum(salary) from employee d where d.emp_no <=
> > running_sume.emp_no
> > 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 <=
> andI have paste two times ! and changed a little,
> > 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.
the second query is not a window example !
When I ran the query, I saw a side effect due to currency values
and added a restriction on job_country in the aggregate query.
>like
>
> > 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
> > sum, count, avg as window functions. they permit detail andof the
> aggregation
> > in the same query.
>
> While I don't know the syntax, I don't see why "e.salary" is part
> order by clause.I have just read the examples from Anthony Molinaro book and frankly,
>
>
> Sean
>
I never used such syntax.
I think order by e.salary in over clause is here to be consistent
with order by 4.
As far as I know, only Oracle 10g, DB2 9 (and MSSQL partially) have
support for window functions.
You could read examples from
http://www.oreilly.com/catalog/sqlpg2/chapter/index.html
Alexandre