GIGA wiki

Funkcje okienkowe w SQL

Migracja; autor Wojtek, ostatnia modyfikacja przed importem 2013-10-07T13:34:10.000Z; Funkcje-okienkowe-w-SQL

Window Functions in SQL Server

Od SQL 2005 są dostępne funkcje agregujące, operujące na danych przed wykonaniem order by i select a po where, group by czy having
Pełną specyfikacje wszystkich funkcji okienkowych implementują dopiero w SQL 2012

MS SQL 2005 do 2008 R2

select funkcja_agregująca( <parametr>) over (partition by po_czym_agregować)
from ...

select count(*) over ( ) ileWszystkich,
      ROW_NUMBER() over (order by YKO_Akronim, yfa_rokfin) as ileFakMaKontrahent,
      Rank() over (order by YKO_Akronim, yfa_rokfin) as ileFakMaKontrahent2,
       count(*) over (partition by yfa_rokfin) as ileFak,
       sum(YFA_Brutto) over (partition by yfa_rokfin) as sumRokFin,
       sum(YFA_Brutto) over (partition by YKO_Akronim, yfa_rokfin) as sumKonRok,
       100*sum(YFA_Brutto) over (partition by YKO_Akronim, yfa_rokfin)/sum(YFA_Brutto) over (partition by yfa_rokfin) as Procent,
       
      -- count(*) over (order by YKO_Akronim) as sumBruttoNarastajacaKonRok,
       
       YFA_RokFin, YFA_Numer, YFA_Seria, YFA_Brutto, convert( datetime, YFA_DataW-36163), YKO_Akronim, YAK_Miasto, YAK_Ulica
from YFaktura, YKontrahent, YAdres_Kontrahent
where YFA_IdKontrahent = YKO_Id and YFA_IdAdres_Kontrahent = YAK_Id  and YKO_Akronim like '001/001' --and YAK_Ulica = 'POŁOMSKA'

OD MS SQL 2012

...