How Add and subtract in query using OVER() function. - TechRepublic
Question
September 11, 2009 at 09:18 AM
naprico

How Add and subtract in query using OVER() function.

by naprico . Updated 16 years, 9 months ago

HI all, I have medium knowldeg of SQL queries. The Add and subtract in the following query has been bothering me for two days. Could someone help explain, in detail every part of the query especially workings of + and -:
suppose min year is 1980 and table has a total of 14 rows. How the results from over and row_number functions add corresponding cells?
select
(
year (min(hiredate)over()) –
year (min(hiredate)over())%10
) +
row_number()over(order by hiredate) -1 yr
from emp
The output is:
1980
1981
1982

1989
Thank you very much.
Naprico

This discussion is locked

All Comments