<s>
In	O
SQL	B-Language
,	O
a	O
window	B-Language
function	I-Language
or	O
analytic	B-Language
function	I-Language
is	O
a	O
function	O
which	O
uses	O
values	O
from	O
one	O
or	O
multiple	O
rows	B-Application
to	O
return	O
a	O
value	O
for	O
each	O
row	O
.	O
</s>
<s>
(	O
This	O
contrasts	O
with	O
an	O
aggregate	O
function	O
,	O
which	O
returns	O
a	O
single	O
value	O
for	O
multiple	O
rows	B-Application
.	O
)	O
</s>
<s>
Window	B-Language
functions	I-Language
have	O
an	O
OVER	O
clause	O
;	O
any	O
function	O
without	O
an	O
OVER	O
clause	O
is	O
not	O
a	O
window	B-Language
function	I-Language
,	O
but	O
rather	O
an	O
aggregate	O
or	O
single-row	O
(	O
scalar	O
)	O
function	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
here	O
is	O
a	O
query	O
which	O
uses	O
a	O
window	B-Language
function	I-Language
to	O
compare	O
the	O
salary	O
of	O
each	O
employee	O
with	O
the	O
average	O
salary	O
of	O
their	O
department	O
(	O
example	O
from	O
the	O
PostgreSQL	B-Application
documentation	O
)	O
:	O
</s>
<s>
The	O
PARTITION	B-Language
BY	I-Language
clause	O
groups	O
rows	B-Application
into	O
partitions	O
,	O
and	O
the	O
function	O
is	O
applied	O
to	O
each	O
partition	O
separately	O
.	O
</s>
<s>
If	O
the	O
PARTITION	B-Language
BY	I-Language
clause	O
is	O
omitted	O
(	O
such	O
as	O
if	O
we	O
have	O
an	O
empty	O
OVER( )	O
clause	O
)	O
,	O
then	O
the	O
entire	O
result	B-Application
set	I-Application
treated	O
as	O
a	O
single	O
partition	O
.	O
</s>
<s>
For	O
this	O
query	O
,	O
the	O
average	O
salary	O
reported	O
would	O
be	O
the	O
average	O
taken	O
over	O
all	O
rows	B-Application
.	O
</s>
<s>
Window	B-Language
functions	I-Language
are	O
evaluated	O
after	O
aggregation	O
(	O
after	O
the	O
GROUP	B-Language
BY	I-Language
clause	O
and	O
non-window	O
aggregate	O
functions	O
,	O
for	O
example	O
)	O
.	O
</s>
<s>
According	O
to	O
the	O
PostgreSQL	B-Application
documentation	O
,	O
a	O
window	B-Language
function	I-Language
has	O
the	O
syntax	O
of	O
one	O
of	O
the	O
following:where	O
window_definition	O
has	O
syntax:frame_clause	O
has	O
the	O
syntax	O
of	O
one	O
of	O
the	O
following:frame_start	O
and	O
frame_end	O
can	O
be	O
UNBOUNDED	O
PRECEDING	O
,	O
offset	O
PRECEDING	O
,	O
CURRENT	O
ROW	O
,	O
offset	O
FOLLOWING	O
,	O
or	O
UNBOUNDED	O
FOLLOWING	O
.	O
</s>
<s>
expression	O
refers	O
to	O
any	O
expression	O
that	O
does	O
not	O
contain	O
a	O
call	O
to	O
a	O
window	B-Language
function	I-Language
.	O
</s>
<s>
Window	B-Language
functions	I-Language
allow	O
access	O
to	O
data	O
in	O
the	O
records	O
right	O
before	O
and	O
after	O
the	O
current	O
record	O
.	O
</s>
<s>
A	O
window	B-Language
function	I-Language
defines	O
a	O
frame	O
or	O
window	O
of	O
rows	B-Application
with	O
a	O
given	O
length	O
around	O
the	O
current	O
row	O
,	O
and	O
performs	O
a	O
calculation	O
across	O
the	O
set	O
of	O
data	O
in	O
the	O
window	O
.	O
</s>
<s>
Window	B-Language
functions	I-Language
were	O
introduced	O
in	O
SQL:2003	B-Language
and	O
had	O
functionality	O
expanded	O
in	O
later	O
specifications	O
.	O
</s>
<s>
MySQL	B-Application
added	O
support	O
for	O
window	B-Language
functions	I-Language
in	O
version	O
8	O
in	O
2018	O
,	O
and	O
MariaDB	B-Application
introduced	O
first	O
window	B-Language
functions	I-Language
with	O
version	O
10.2	O
.	O
</s>
