0% found this document useful (0 votes)
20 views

S03-Window Functions Within SQLite

Uploaded by

AB
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

S03-Window Functions Within SQLite

Uploaded by

AB
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

7/25/24, 4:13 PM s03-Window Functions within SQLite.

ipynb - Colab

keyboard_arrow_down s03-Window Functions within SQLite


Window Functions get available sincle SQLite 3.25.According to the SQLite docs:

A window function is a special SQL function where the input values are taken from a
“window” of one or more rows in the results set of a SELECT statement.

SQLite now has these built-in Window functions:

row_number()
rank()
dense_rank()
percent_rank()
cume_dist()
ntile(N)
lag(expr), lag(expr, offset), lag(expr, offset, default)
lead(expr), lead(expr, offset), lead(expr, offset, default)
first_value(expr)
last_value(expr)
nth_value(expr, N)

Previous tutorials are created based on a little bit older SQLite versions. At that time, window
Functions are not available. In this tutoiral, I am going to touch some of them in the following 5
sections:

Firstly, give a comparison between SQL Window Functions vs. SQL Aggregate Functions

Secondly, go through a few WINDOW functions based on regular aggregate functions, such as
AVG, MIN/MAX, COUNT, SUM.

Thirdly, focus on rank-related functions, such as ROW_NUMBER, RANK,and RANK_DENSE.


Those functions are handy when generating ranking indexes, and you need to be fluent in
those functions before entering a data scientist SQL interview.

Forthly, talk about generating statistics (e.g., percentiles, quartiles, median, etc .) with the
NTILE function, a common task for a data scientist.

Fifthly, focus on LAG and LEAD, two functions that are super important if you are interviewing
for a role that requires dealing with time-series data.

1. Window Functions vs. Aggregate Functions

https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 1/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

In the previous tutorials, we presented some application cases of Aggregate Functions. What are
the Similarities and Differences between them? Let's have a quick gothrough.

1.1 Aggregate functions


Aggregate functions operate on a set of values to return a single scalar value. These are SQL
aggregate functions:

AVG() returns the average of the specified values.


SUM() calculates the sum of all values in the set.
MAX() and MIN() return the maximum and minimum value, respectively.
COUNT() returns the total number of values in the set.

By using the GROUP BY clause, you can calculate an aggregate value for several groups in one
query. That is to say, aggregate functions collapse the individual rows and present the aggregate
value for all the rows in the group.

1.2 Window functions


Window functions operate on a set of rows called a window frame. They return a single value for
each row from the underlying query.

The window frame (or simply window) is defined using the OVER() clause. This clause also allows
defining a window based on a specific column (similar to GROUP BY).

To calculate the returned values, window functions may use aggregate functions, but they will use
them with the OVER() clause.

1.3 Similarities and Differences Between Window and Aggregate Functions


Now that we have seen both types of functions, we can summarize the similarities and differences
between them.

Both window functions and aggregate functions:

Operate on a set of values (rows).


Can calculate aggregate amounts (e.g. AVG(), SUM(), MAX(), MIN(), or COUNT()) on the set.
Can group or partition data on one or more columns.

Aggregate functions with GROUP BY differ from window functions in that they:

Use GROUP BY() to define a set of rows for aggregation.


Group rows based on column values.
Collapse rows based on the defined groups.

Window functions differ from aggregate functions used with GROUP BY in that they:

Use OVER() instead of GROUP BY() to define a set of rows.


https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 2/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

May use many functions other than aggregates (e.g. RANK(), LAG(), or LEAD()).
Groups rows on the row’s rank, percentile, etc. as well as its column value.
Do not collapse rows.
May use a sliding window frame (which depends on the current row).

keyboard_arrow_down 2. Practive window functions


Let's connect the demo database, firstly.

%load_ext sql

The sql extension is already loaded. To reload it, use:


%reload_ext sql

%sql sqlite:///data/demo.db3

'Connected: @data/demo.db3'

keyboard_arrow_down MIN/MAX, SUM, COUNT


2.1 WINDOW functions based on regular aggregate functions: AVG,

Window functions are functions that perform calculations across a set of rows related to the
current row.

It is comparable to the type of calculation done with an aggregate function, but unlike regular
aggregate functions, window functions do not group several rows into a single output row — the
rows retain their own identities.

Behind the scenes, the window functions process more than just the query results' current row.

Let's take the watershed_monthly as the demo table.

2.1.1 AVG

%%sql sqlite://
SELECT
YR,
MO,
PREC_mm,
ROUND(AVG(PREC_mm) OVER(PARTITION BY MO)) AS avg_PREC_mm
FROM watershed_monthly
ORDER by MO

https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 3/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

Done.
YR MO PREC_mm avg_PREC_mm
1981 1 96.2901611328125 114.0
1982 1 59.744789123535156 114.0
1983 1 94.48113250732422 114.0
1984 1 111.43696594238281 114.0
1985 1 78.43978881835938 114.0
1986 1 45.433536529541016 114.0
1987 1 146.7594757080078 114.0
1988 1 106.8199234008789 114.0
1989 1 97.1476821899414 114.0
1990 1 84.20606994628906 114.0
1991 1 120.2723388671875 114.0
1992 1 114.5992660522461 114.0
1993 1 139.7407684326172 114.0
1994 1 117.82371520996094 114.0
1995 1 99.79764556884766 114.0
1996 1 171.72898864746094 114.0
1997 1 109.2258529663086 114.0
1998 1 165.39779663085938 114.0
1999 1 129.19338989257812 114.0
2000 1 81.89866638183594 114.0
2001 1 66.61447143554688 114.0
2002 1 125.24539184570312 114.0
2003 1 137.62448120117188 114.0
2004 1 116.2384262084961 114.0
2005 1 178.54624938964844 114.0
2006 1 99.33370971679688 114.0
2007 1 206.89495849609375 114.0
2008 1 77.4709701538086 114.0
2009 1 122.1943359375 114.0
2010 1 107.7326431274414 114.0
1981 2 160.22804260253906 119.0
1982 2 87.51470184326172 119.0
1983 2 52.12006378173828 119.0
1984 2 163.99578857421875 119.0
1985 2 130.32330322265625 119.0
1986 2 110.43309020996094 119.0
1987 2 184.14231872558594 119.0
1988 2 183.34051513671875 119.0
1989 2 117.50041961669922 119.0
1990 2 116.64447021484375 119.0
1991 2 113.96415710449219 119.0
1992 2 189.6724853515625 119.0
1993 2 136.2637939453125 119.0
1994 2 158.59536743164062 119.0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 4/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

1995 2 124.73197174072266 119.0


1996 2 181.6288604736328 119.0
1997 2 110.37721252441406 119.0
1998 2 118.6283187866211 119.0
1999 2 97.8355712890625 119.0
2000 2 48.70695114135742 119.0
2001 2 47.3634033203125 119.0
2002 2 105.65862274169922 119.0
2003 2 113.89664459228516 119.0
2004 2 110.6496353149414 119.0
2005 2 56.347206115722656 119.0
2006 2 55.579612731933594 119.0
2007 2 55.45048141479492 119.0
2008 2 95.09587860107422 119.0
2009 2 161.8676300048828 119.0
2010 2 173.24346923828125 119.0
1981 3 136.6529083251953 99.0
1982 3 150.9921875 99.0
1983 3 129.8241729736328 99.0
1984 3 104.96453857421875 99.0
1985 3 99.34416198730469 99.0
1986 3 108.29244232177734 99.0
1987 3 121.24017333984375 99.0
1988 3 127.04043579101562 99.0
1989 3 115.449462890625 99.0
1990 3 110.31065368652344 99.0
1991 3 122.04442596435547 99.0
1992 3 160.9407501220703 99.0
1993 3 133.84007263183594 99.0
1994 3 106.6016616821289 99.0
1995 3 122.27830505371094 99.0
1996 3 132.6336212158203 99.0
1997 3 104.50662231445312 99.0
1998 3 149.83721923828125 99.0
1999 3 38.80699920654297 99.0
2000 3 19.893341064453125 99.0
2001 3 11.640951156616211 99.0
2002 3 44.062137603759766 99.0
2003 3 47.003868103027344 99.0
2004 3 49.31222152709961 99.0
2005 3 96.73483276367188 99.0
2006 3 26.39670181274414 99.0
2007 3 100.57988739013672 99.0
2008 3 52.47661590576172 99.0
2009 3 122.73454284667969 99.0
2010 3 110 05859375 99 0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 5/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
2010 3 110.05859375 99.0
1981 4 118.85740661621094 69.0
1982 4 97.7410659790039 69.0
1983 4 163.90794372558594 69.0
1984 4 95.60626220703125 69.0
1985 4 81.7612075805664 69.0
1986 4 71.4702377319336 69.0
1987 4 77.35852813720703 69.0
1988 4 82.293212890625 69.0
1989 4 91.74241638183594 69.0
1990 4 69.09127044677734 69.0
1991 4 105.03886413574219 69.0
1992 4 117.70687866210938 69.0
1993 4 168.93685913085938 69.0
1994 4 61.40770721435547 69.0
1995 4 85.01670837402344 69.0
1996 4 59.92761993408203 69.0
1997 4 51.581851959228516 69.0
1998 4 72.07745361328125 69.0
1999 4 22.82688331604004 69.0
2000 4 12.554158210754395 69.0
2001 4 16.332597732543945 69.0
2002 4 21.45844268798828 69.0
2003 4 13.530596733093262 69.0
2004 4 22.2083740234375 69.0
2005 4 38.1638298034668 69.0
2006 4 26.746002197265625 69.0
2007 4 40.11917495727539 69.0
2008 4 10.628643989562988 69.0
2009 4 81.78004455566406 69.0
2010 4 77.36785125732422 69.0
1981 5 84.54698181152344 33.0
1982 5 87.78800201416016 33.0
1983 5 88.9581527709961 33.0
1984 5 14.243524551391602 33.0
1985 5 48.69215393066406 33.0
1986 5 34.66059494018555 33.0
1987 5 35.985435485839844 33.0
1988 5 47.07449722290039 33.0
1989 5 61.8648796081543 33.0
1990 5 39.08815002441406 33.0
1991 5 60.08303451538086 33.0
1992 5 35.77204132080078 33.0
1993 5 55.35698699951172 33.0
1994 5 24.38063621520996 33.0
1995 5 26.521377563476562 33.0
1996 5 26 67353057861328 33 0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 6/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
1996 5 26.67353057861328 33.0
1997 5 14.8255615234375 33.0
1998 5 39.28791809082031 33.0
1999 5 11.534664154052734 33.0
2000 5 11.022218704223633 33.0
2001 5 4.57631254196167 33.0
2002 5 10.422792434692383 33.0
2003 5 3.178541898727417 33.0
2004 5 32.50706100463867 33.0
2005 5 16.846424102783203 33.0
2006 5 6.052229404449463 33.0
2007 5 19.25904083251953 33.0
2008 5 7.693519592285156 33.0
2009 5 7.703615188598633 33.0
2010 5 37.19248962402344 33.0
1981 6 44.83718490600586 23.0
1982 6 62.78643035888672 23.0
1983 6 65.43035888671875 23.0
1984 6 43.40272521972656 23.0
1985 6 16.78373908996582 23.0
1986 6 27.704425811767578 23.0
1987 6 74.57366943359375 23.0
1988 6 23.411775588989258 23.0
1989 6 55.292442321777344 23.0
1990 6 20.2957763671875 23.0
1991 6 13.56886100769043 23.0
1992 6 18.79245376586914 23.0
1993 6 39.68621063232422 23.0
1994 6 3.8289220333099365 23.0
1995 6 13.049528121948242 23.0
1996 6 18.90243148803711 23.0
1997 6 3.311275005340576 23.0
1998 6 21.41149139404297 23.0
1999 6 16.968156814575195 23.0
2000 6 2.1060729026794434 23.0
2001 6 7.757592678070068 23.0
2002 6 5.1767730712890625 23.0
2003 6 10.518081665039062 23.0
2004 6 7.882723808288574 23.0
2005 6 16.190933227539062 23.0
2006 6 10.887991905212402 23.0
2007 6 9.5333890914917 23.0
2008 6 15.11318302154541 23.0
2009 6 6.912513732910156 23.0
2010 6 21.425451278686523 23.0
1981 7 32.325984954833984 19.0
1982 7 22 69496726989746 19 0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 7/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
1982 7 22.69496726989746 19.0
1983 7 52.85027313232422 19.0
1984 7 34.1981315612793 19.0
1985 7 10.127609252929688 19.0
1986 7 28.09088134765625 19.0
1987 7 33.39873504638672 19.0
1988 7 20.721471786499023 19.0
1989 7 24.988685607910156 19.0
1990 7 8.136661529541016 19.0
1991 7 9.473738670349121 19.0
1992 7 17.575836181640625 19.0
1993 7 13.32302474975586 19.0
1994 7 5.31728458404541 19.0
1995 7 7.277742385864258 19.0
1996 7 4.332550525665283 19.0
1997 7 2.399183750152588 19.0
1998 7 10.958629608154297 19.0
1999 7 27.09001350402832 19.0
2000 7 36.59354782104492 19.0
2001 7 10.02917194366455 19.0
2002 7 13.134001731872559 19.0
2003 7 35.86302185058594 19.0
2004 7 17.656644821166992 19.0
2005 7 7.210659503936768 19.0
2006 7 11.554990768432617 19.0
2007 7 7.517814636230469 19.0
2008 7 11.83874797821045 19.0
2009 7 22.063232421875 19.0
2010 7 40.155967712402344 19.0
1981 8 20.65149688720703 27.0
1982 8 17.83991050720215 27.0
1983 8 21.578163146972656 27.0
1984 8 15.824188232421875 27.0
1985 8 10.73428726196289 27.0
1986 8 40.33757019042969 27.0
1987 8 20.907390594482422 27.0
1988 8 30.90254783630371 27.0
1989 8 23.658241271972656 27.0
1990 8 3.512204170227051 27.0
1991 8 54.519954681396484 27.0
1992 8 12.080037117004395 27.0
1993 8 16.8857421875 27.0
1994 8 46.66091537475586 27.0
1995 8 11.950968742370605 27.0
1996 8 15.782317161560059 27.0
1997 8 3.7355682849884033 27.0
1998 8 10 963287353515625 27 0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 8/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
1998 8 10.963287353515625 27.0
1999 8 34.96633529663086 27.0
2000 8 33.62543487548828 27.0
2001 8 57.558448791503906 27.0
2002 8 14.20559310913086 27.0
2003 8 32.29594802856445 27.0
2004 8 42.52296829223633 27.0
2005 8 25.277902603149414 27.0
2006 8 30.839567184448242 27.0
2007 8 9.534032821655273 27.0
2008 8 66.79488372802734 27.0
2009 8 41.06700897216797 27.0
2010 8 54.445960998535156 27.0
1981 9 16.57965660095215 52.0
1982 9 18.683820724487305 52.0
1983 9 12.654004096984863 52.0
1984 9 39.768798828125 52.0
1985 9 33.53099822998047 52.0
1986 9 27.095539093017578 52.0
1987 9 109.45503234863281 52.0
1988 9 39.20307159423828 52.0
1989 9 46.295372009277344 52.0
1990 9 51.724674224853516 52.0
1991 9 30.19475746154785 52.0
1992 9 23.477638244628906 52.0
1993 9 70.33382415771484 52.0
1994 9 49.03969192504883 52.0
1995 9 45.632041931152344 52.0
1996 9 51.23722457885742 52.0
1997 9 42.12110137939453 52.0
1998 9 16.724767684936523 52.0
1999 9 117.02091979980469 52.0
2000 9 84.15239715576172 52.0
2001 9 53.744712829589844 52.0
2002 9 46.71512985229492 52.0
2003 9 69.0370864868164 52.0
2004 9 91.2891845703125 52.0
2005 9 62.30735778808594 52.0
2006 9 117.03430938720703 52.0
2007 9 45.0174560546875 52.0
2008 9 40.83495330810547 52.0
2009 9 93.35775756835938 52.0
2010 9 12.318583488464355 52.0
1981 10 59.67293167114258 66.0
1982 10 107.47823333740234 66.0
1983 10 43.64889144897461 66.0
1984 10 85 201416015625 66 0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 9/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
1984 10 85.201416015625 66.0
1985 10 33.29714584350586 66.0
1986 10 75.63070678710938 66.0
1987 10 31.48656463623047 66.0
1988 10 28.865161895751953 66.0
1989 10 81.45527648925781 66.0
1990 10 17.68677520751953 66.0
1991 10 87.55663299560547 66.0
1992 10 43.805694580078125 66.0
1993 10 123.36309814453125 66.0
1994 10 116.16419219970703 66.0
1995 10 33.60626220703125 66.0
1996 10 27.233800888061523 66.0
1997 10 55.565643310546875 66.0
1998 10 48.46929168701172 66.0
1999 10 16.439165115356445 66.0
2000 10 46.88323211669922 66.0
2001 10 56.345924377441406 66.0
2002 10 93.52913665771484 66.0
2003 10 87.20095825195312 66.0
2004 10 122.78729248046875 66.0
2005 10 52.69425582885742 66.0
2006 10 44.077369689941406 66.0
2007 10 138.5694122314453 66.0
2008 10 115.79918670654297 66.0
2009 10 76.02496337890625 66.0
2010 10 24.513809204101562 66.0
1981 11 52.78509521484375 86.0
1982 11 112.13990783691406 86.0
1983 11 48.36265182495117 86.0
1984 11 84.40652465820312 86.0
1985 11 62.19684982299805 86.0
1986 11 115.95671844482422 86.0
1987 11 88.3420639038086 86.0
1988 11 134.65943908691406 86.0
1989 11 90.58506774902344 86.0
1990 11 120.88981628417969 86.0
1991 11 169.23207092285156 86.0
1992 11 107.41029357910156 86.0
1993 11 63.52189254760742 86.0
1994 11 53.50334548950195 86.0
1995 11 50.98604965209961 86.0
1996 11 35.49591064453125 86.0
1997 11 80.97866821289062 86.0
1998 11 32.96993637084961 86.0
1999 11 74.87493133544922 86.0
2000 11 52 33726119995117 86 0
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 10/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
2000 11 52.33726119995117 86.0
2001 11 92.82563018798828 86.0
2002 11 56.953712463378906 86.0
2003 11 81.39073181152344 86.0
2004 11 105.43321228027344 86.0
2005 11 162.82516479492188 86.0
2006 11 73.37273406982422 86.0
2007 11 56.59675216674805 86.0
2008 11 93.5806655883789 86.0
2009 11 120.41217041015625 86.0
2010 11 93.515625 86.0
1981 12 72.17727661132812 97.0
1982 12 59.266727447509766 97.0
1983 12 42.84471130371094 97.0
1984 12 74.52552795410156 97.0
1985 12 32.49427032470703 97.0
1986 12 48.73545455932617 97.0
1987 12 84.24513244628906 97.0
1988 12 71.5145034790039 97.0
1989 12 124.12555694580078 97.0
1990 12 109.86883544921875 97.0
1991 12 98.52151489257812 97.0
1992 12 66.11283874511719 97.0
1993 12 96.52111053466797 97.0
1994 12 58.802764892578125 97.0
1995 12 76.00419616699219 97.0
1996 12 74.39060974121094 97.0
1997 12 110.74897003173828 97.0
1998 12 156.7340545654297 97.0
1999 12 56.744571685791016 97.0
2000 12 68.1783447265625 97.0
2001 12 87.46170806884766 97.0
2002 12 165.4676055908203 97.0
2003 12 98.40425109863281 97.0
2004 12 99 89029693603516 97 0
There is no GROUP BY clause for the AVG function, but how does the SQL engine know which rows
to use to compute the average? The answer is the PARTITION BY clause inside the OVER() utility,
and we are calculating the average based on a unique value of rating.

In the final output, every row has the average PREC_mm from the same month (MO). By adding a
ORDER by, you will find there is the same averge value for each month.

keyboard_arrow_down 2.1.2 SUM

https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 11/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

Let’s take a look at a more complicated example, where we calculated a running sum with a window
function.

%%sql sqlite://
SELECT
YR,
MO,
PREC_mm,
SUM(PREC_mm) OVER(ORDER BY MO) AS running_total,
SUM(PREC_mm) OVER() AS overall,
ROUND(SUM(PREC_mm) OVER(ORDER BY MO) * 100.0 /SUM(PREC_mm) OVER(), 2) AS running_percent
FROM watershed_monthly

https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 12/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

Done.
YR MO PREC_mm running_total overall running_percentage
1981 1 96.2901611328125 3408.3335914611816 24084.3432366848 14.15
1982 1 59.744789123535156 3408.3335914611816 24084.3432366848 14.15
1983 1 94.48113250732422 3408.3335914611816 24084.3432366848 14.15
1984 1 111.43696594238281 3408.3335914611816 24084.3432366848 14.15
1985 1 78.43978881835938 3408.3335914611816 24084.3432366848 14.15
1986 1 45.433536529541016 3408.3335914611816 24084.3432366848 14.15
1987 1 146.7594757080078 3408.3335914611816 24084.3432366848 14.15
1988 1 106.8199234008789 3408.3335914611816 24084.3432366848 14.15
1989 1 97.1476821899414 3408.3335914611816 24084.3432366848 14.15
1990 1 84.20606994628906 3408.3335914611816 24084.3432366848 14.15
1991 1 120.2723388671875 3408.3335914611816 24084.3432366848 14.15
1992 1 114.5992660522461 3408.3335914611816 24084.3432366848 14.15
1993 1 139.7407684326172 3408.3335914611816 24084.3432366848 14.15
1994 1 117.82371520996094 3408.3335914611816 24084.3432366848 14.15
1995 1 99.79764556884766 3408.3335914611816 24084.3432366848 14.15
1996 1 171.72898864746094 3408.3335914611816 24084.3432366848 14.15
1997 1 109.2258529663086 3408.3335914611816 24084.3432366848 14.15
1998 1 165.39779663085938 3408.3335914611816 24084.3432366848 14.15
1999 1 129.19338989257812 3408.3335914611816 24084.3432366848 14.15
2000 1 81.89866638183594 3408.3335914611816 24084.3432366848 14.15
2001 1 66.61447143554688 3408.3335914611816 24084.3432366848 14.15
2002 1 125.24539184570312 3408.3335914611816 24084.3432366848 14.15
2003 1 137.62448120117188 3408.3335914611816 24084.3432366848 14.15
2004 1 116.2384262084961 3408.3335914611816 24084.3432366848 14.15
2005 1 178.54624938964844 3408.3335914611816 24084.3432366848 14.15
2006 1 99.33370971679688 3408.3335914611816 24084.3432366848 14.15
2007 1 206.89495849609375 3408.3335914611816 24084.3432366848 14.15
2008 1 77.4709701538086 3408.3335914611816 24084.3432366848 14.15
2009 1 122.1943359375 3408.3335914611816 24084.3432366848 14.15
2010 1 107.7326431274414 3408.3335914611816 24084.3432366848 14.15
1981 2 160.22804260253906 6970.13357925415 24084.3432366848 28.94
1982 2 87.51470184326172 6970.13357925415 24084.3432366848 28.94
1983 2 52.12006378173828 6970.13357925415 24084.3432366848 28.94
1984 2 163.99578857421875 6970.13357925415 24084.3432366848 28.94
1985 2 130.32330322265625 6970.13357925415 24084.3432366848 28.94
1986 2 110.43309020996094 6970.13357925415 24084.3432366848 28.94
1987 2 184.14231872558594 6970.13357925415 24084.3432366848 28.94
1988 2 183.34051513671875 6970.13357925415 24084.3432366848 28.94
1989 2 117.50041961669922 6970.13357925415 24084.3432366848 28.94
1990 2 116.64447021484375 6970.13357925415 24084.3432366848 28.94
1991 2 113.96415710449219 6970.13357925415 24084.3432366848 28.94
1992 2 189.6724853515625 6970.13357925415 24084.3432366848 28.94
1993 2 136.2637939453125 6970.13357925415 24084.3432366848 28.94
1994 2 158.59536743164062 6970.13357925415 24084.3432366848 28.94
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 13/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab

1995 2 124.73197174072266 6970.13357925415 24084.3432366848 28.94


1996 2 181.6288604736328 6970.13357925415 24084.3432366848 28.94
1997 2 110.37721252441406 6970.13357925415 24084.3432366848 28.94
1998 2 118.6283187866211 6970.13357925415 24084.3432366848 28.94
1999 2 97.8355712890625 6970.13357925415 24084.3432366848 28.94
2000 2 48.70695114135742 6970.13357925415 24084.3432366848 28.94
2001 2 47.3634033203125 6970.13357925415 24084.3432366848 28.94
2002 2 105.65862274169922 6970.13357925415 24084.3432366848 28.94
2003 2 113.89664459228516 6970.13357925415 24084.3432366848 28.94
2004 2 110.6496353149414 6970.13357925415 24084.3432366848 28.94
2005 2 56.347206115722656 6970.13357925415 24084.3432366848 28.94
2006 2 55.579612731933594 6970.13357925415 24084.3432366848 28.94
2007 2 55.45048141479492 6970.13357925415 24084.3432366848 28.94
2008 2 95.09587860107422 6970.13357925415 24084.3432366848 28.94
2009 2 161.8676300048828 6970.13357925415 24084.3432366848 28.94
2010 2 173.24346923828125 6970.13357925415 24084.3432366848 28.94
1981 3 136.6529083251953 9926.628087997437 24084.3432366848 41.22
1982 3 150.9921875 9926.628087997437 24084.3432366848 41.22
1983 3 129.8241729736328 9926.628087997437 24084.3432366848 41.22
1984 3 104.96453857421875 9926.628087997437 24084.3432366848 41.22
1985 3 99.34416198730469 9926.628087997437 24084.3432366848 41.22
1986 3 108.29244232177734 9926.628087997437 24084.3432366848 41.22
1987 3 121.24017333984375 9926.628087997437 24084.3432366848 41.22
1988 3 127.04043579101562 9926.628087997437 24084.3432366848 41.22
1989 3 115.449462890625 9926.628087997437 24084.3432366848 41.22
1990 3 110.31065368652344 9926.628087997437 24084.3432366848 41.22
1991 3 122.04442596435547 9926.628087997437 24084.3432366848 41.22
1992 3 160.9407501220703 9926.628087997437 24084.3432366848 41.22
1993 3 133.84007263183594 9926.628087997437 24084.3432366848 41.22
1994 3 106.6016616821289 9926.628087997437 24084.3432366848 41.22
1995 3 122.27830505371094 9926.628087997437 24084.3432366848 41.22
1996 3 132.6336212158203 9926.628087997437 24084.3432366848 41.22
1997 3 104.50662231445312 9926.628087997437 24084.3432366848 41.22
1998 3 149.83721923828125 9926.628087997437 24084.3432366848 41.22
1999 3 38.80699920654297 9926.628087997437 24084.3432366848 41.22
2000 3 19.893341064453125 9926.628087997437 24084.3432366848 41.22
2001 3 11.640951156616211 9926.628087997437 24084.3432366848 41.22
2002 3 44.062137603759766 9926.628087997437 24084.3432366848 41.22
2003 3 47.003868103027344 9926.628087997437 24084.3432366848 41.22
2004 3 49.31222152709961 9926.628087997437 24084.3432366848 41.22
2005 3 96.73483276367188 9926.628087997437 24084.3432366848 41.22
2006 3 26.39670181274414 9926.628087997437 24084.3432366848 41.22
2007 3 100.57988739013672 9926.628087997437 24084.3432366848 41.22
2008 3 52.47661590576172 9926.628087997437 24084.3432366848 41.22
2009 3 122.73454284667969 9926.628087997437 24084.3432366848 41.22
2010 3 110 05859375 9926 628087997437 24084 3432366848 41 22
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 14/15
7/25/24, 4:13 PM s03-Window Functions within SQLite.ipynb - Colab
2010 3 110.05859375 9926.628087997437 24084.3432366848 41.22
1981 4 118.85740661621094 11981.868182182312 24084.3432366848 49.75
1982 4 97.7410659790039 11981.868182182312 24084.3432366848 49.75
1983 4 163.90794372558594 11981.868182182312 24084.3432366848 49.75
1984 4 95.60626220703125 11981.868182182312 24084.3432366848 49.75
1985 4 81.7612075805664 11981.868182182312 24084.3432366848 49.75
1986 4 71.4702377319336 11981.868182182312 24084.3432366848 49.75
1987 4 77.35852813720703 11981.868182182312 24084.3432366848 49.75
1988 4 82.293212890625 11981.868182182312 24084.3432366848 49.75
1989 4 91.74241638183594 11981.868182182312 24084.3432366848 49.75
1990 4 69.09127044677734 11981.868182182312 24084.3432366848 49.75
1991 4 105.03886413574219 11981.868182182312 24084.3432366848 49.75
1992 4 117.70687866210938 11981.868182182312 24084.3432366848 49.75
1993 4 168.93685913085938 11981.868182182312 24084.3432366848 49.75
1994 4 61.40770721435547 11981.868182182312 24084.3432366848 49.75
1995 4 85.01670837402344 11981.868182182312 24084.3432366848 49.75
1996 4 59.92761993408203 11981.868182182312 24084.3432366848 49.75
1997 4 51.581851959228516 11981.868182182312 24084.3432366848 49.75
1998 4 72.07745361328125 11981.868182182312 24084.3432366848 49.75
1999 4 22.82688331604004 11981.868182182312 24084.3432366848 49.75
2000 4 12.554158210754395 11981.868182182312 24084.3432366848 49.75
2001 4 16.332597732543945 11981.868182182312 24084.3432366848 49.75
2002 4 21.45844268798828 11981.868182182312 24084.3432366848 49.75
2003 4 13.530596733093262 11981.868182182312 24084.3432366848 49.75
2004 4 22.2083740234375 11981.868182182312 24084.3432366848 49.75
2005 4 38.1638298034668 11981.868182182312 24084.3432366848 49.75
2006 4 26.746002197265625 11981.868182182312 24084.3432366848 49.75
2007 4 40.11917495727539 11981.868182182312 24084.3432366848 49.75
2008 4 10.628643989562988 11981.868182182312 24084.3432366848 49.75
2009 4 81.78004455566406 11981.868182182312 24084.3432366848 49.75
2010 4 77.36785125732422 11981.868182182312 24084.3432366848 49.75
1981 5 84.54698181152344 12975.660550832748 24084.3432366848 53.88
1982 5 87.78800201416016 12975.660550832748 24084.3432366848 53.88
1983 5 88.9581527709961 12975.660550832748 24084.3432366848 53.88
1984 5 14.243524551391602 12975.660550832748 24084.3432366848 53.88
1985 5 48.69215393066406 12975.660550832748 24084.3432366848 53.88
1986 5 34.66059494018555 12975.660550832748 24084.3432366848 53.88
1987 5 35.985435485839844 12975.660550832748 24084.3432366848 53.88
1988 5 47.07449722290039 12975.660550832748 24084.3432366848 53.88
1989 5 61.8648796081543 12975.660550832748 24084.3432366848 53.88
1990 5 39.08815002441406 12975.660550832748 24084.3432366848 53.88
1991 5 60.08303451538086 12975.660550832748 24084.3432366848 53.88
1992 5 35.77204132080078 12975.660550832748 24084.3432366848 53.88
1993 5 55.35698699951172 12975.660550832748 24084.3432366848 53.88
1994 5 24.38063621520996 12975.660550832748 24084.3432366848 53.88
1995 5 26.521377563476562 12975.660550832748 24084.3432366848 53.88
1996 5 26 67353057861328 12975 660550832748 24084 3432366848 53 88
https://colab.research.google.com/drive/15x1e1H_D-7M4TjgT1i3lp6f3oC8jmu_z#printMode=true 15/15

You might also like