Introduction
FIRST_VALUE, LAST_VALUE, NTH_VALUE
18. LAST_VALUE(x) with window frame
Summary

## Instruction

Well... The query didn't work! Instead of the latest opening date, we saw the current opening date.

In order to understand why this happened, we need to refer to the previous part of our course, where we talked about default window frames:

If there is an ORDER BY clause, RANGE UNBOUNDED PRECEDING will be used as the default window frame.

And this is precisely the cause of our troubles. We indeed used ORDER BY within OVER(...), which is why LAST_VALUE(x) only considers the rows from the first row until the current row. The solution is quite simple: we need to define the right window frame:

SELECT
name,
opened,
LAST_VALUE(opened) OVER(
ORDER BY opened
ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING)
FROM website;


## Exercise

Alright, let's run the new template to see if it works.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.4703477621078491, "perplexity": 2486.123601304035}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-09/segments/1550247495001.53/warc/CC-MAIN-20190220125916-20190220151916-00336.warc.gz"}