{"id":1659,"date":"2018-11-04T18:12:01","date_gmt":"2018-11-04T11:12:01","guid":{"rendered":"http:\/\/www.sqlitetutorial.net\/?page_id=1659"},"modified":"2024-10-25T14:57:26","modified_gmt":"2024-10-25T07:57:26","slug":"sqlite-window-functions","status":"publish","type":"page","link":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/","title":{"rendered":"SQLite Window Functions"},"content":{"rendered":"\n<p>An SQLite window function performs a calculation on a set of rows that are related to the current row. Unlike an&nbsp;<a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-aggregate-functions\/\">aggregate function<\/a>, a window function does not cause rows to become grouped into a single result row. a window function retains the row identities. Behind the scenes, window functions can access more than just the current row of the query result.<\/p>\n\n\n\n<p>The following picture illustrates the differences between aggregate functions and window functions:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"841\" height=\"314\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-window-function-vs-aggregate-function.png\" alt=\"SQLite window function vs aggregate function\" class=\"wp-image-1766\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-window-function-vs-aggregate-function.png 841w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-window-function-vs-aggregate-function-300x112.png 300w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-window-function-vs-aggregate-function-768x287.png 768w\" sizes=\"auto, (max-width: 841px) 100vw, 841px\" \/><\/figure>\n\n\n\n<p>The window functions are divided into three categories: value window functions, ranking window functions, and aggregate window functions as shown in the following picture:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"518\" height=\"346\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions-1.png\" alt=\"SQLite Window Functions\" class=\"wp-image-1723\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions-1.png 518w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions-1-300x200.png 300w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/figure><\/div>\n\n\n\n<p>Window functions are also known as analytic functions. The following table shows all window functions supported by SQLite:<br>\n<input id=\"search\" class=\"light-table-filter\" type=\"text\" placeholder=\"Type a function name to search...\" data-table=\"functions\"><\/p>\n\n\n\n<figure class=\"wp-block-table responsive functions\"><table class=\"\"><thead><tr><th>Name<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-cume_dist\/\">CUME_DIST<\/a><\/td><td>Compute the cumulative distribution of a value in an ordered set of values.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-dense_rank\/\">DENSE_RANK<\/a><\/td><td>Compute the rank for a row in an ordered set of rows with no gaps in rank values.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-first_value\/\">FIRST_VALUE<\/a><\/td><td>Get the value of the first row in a specified window frame.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-lag\/\">LAG<\/a><\/td><td>Provide access to a row at a given physical offset that comes before the current row.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-last_value\/\">LAST_VALUE<\/a><\/td><td>Get the value of the last row in a specified window frame.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-lead\/\">LEAD<\/a><\/td><td>Provide access to a row at a given physical offset that follows the current row.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-nth_value\/\">NTH_VALUE<\/a><\/td><td>Return the value of an expression&nbsp;evaluated against the row&nbsp;N&nbsp;of the window frame in the result set.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-ntile\/\">NTILE<\/a><\/td><td>Divide a result set into a number of buckets as evenly as possible and assign a bucket number to each row.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-percent_rank\/\">PERCENT_RANK<\/a><\/td><td>Calculate the percent rank of each&nbsp;row in an ordered set of rows.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-rank\/\">RANK<\/a><\/td><td>Assign a rank to each row within the partition of the result set.<\/td><\/tr><tr><td><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-row_number\/\">ROW_NUMBER<\/a><\/td><td>Assign a sequential integer starting from one to each row within the current partition.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>SQLite window functions perform a calculation on a set of rows that are related to the current row. Unlike aggregate functions, window functions do not cause rows to become grouped into a single result row.<\/p>\n","protected":false},"author":1,"featured_media":1688,"parent":0,"menu_order":9,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1659","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQLite Window Functions<\/title>\n<meta name=\"description\" content=\"SQLite window functions allow you to perform a calculation on a set of rows that are related to the current row.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQLite Window Functions\" \/>\n<meta property=\"og:description\" content=\"SQLite window functions allow you to perform a calculation on a set of rows that are related to the current row.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"SQLite Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-25T07:57:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427\"},\"headline\":\"SQLite Window Functions\",\"datePublished\":\"2018-11-04T11:12:01+00:00\",\"dateModified\":\"2024-10-25T07:57:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\"},\"wordCount\":310,\"image\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\",\"url\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\",\"name\":\"SQLite Window Functions\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png\",\"datePublished\":\"2018-11-04T11:12:01+00:00\",\"dateModified\":\"2024-10-25T07:57:26+00:00\",\"description\":\"SQLite window functions allow you to perform a calculation on a set of rows that are related to the current row.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage\",\"url\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png\",\"contentUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png\",\"width\":512,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlitetutorial.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQLite Window Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#website\",\"url\":\"https:\/\/www.sqlitetutorial.net\/\",\"name\":\"SQLite Tutorial\",\"description\":\"A Step-by-step SQLite Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlitetutorial.net\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427\",\"name\":\"admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQLite Window Functions","description":"SQLite window functions allow you to perform a calculation on a set of rows that are related to the current row.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/","og_locale":"en_US","og_type":"article","og_title":"SQLite Window Functions","og_description":"SQLite window functions allow you to perform a calculation on a set of rows that are related to the current row.","og_url":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/","og_site_name":"SQLite Tutorial","article_modified_time":"2024-10-25T07:57:26+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#article","isPartOf":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/"},"author":{"name":"admin","@id":"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427"},"headline":"SQLite Window Functions","datePublished":"2018-11-04T11:12:01+00:00","dateModified":"2024-10-25T07:57:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/"},"wordCount":310,"image":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/","url":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/","name":"SQLite Window Functions","isPartOf":{"@id":"https:\/\/www.sqlitetutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png","datePublished":"2018-11-04T11:12:01+00:00","dateModified":"2024-10-25T07:57:26+00:00","description":"SQLite window functions allow you to perform a calculation on a set of rows that are related to the current row.","breadcrumb":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#primaryimage","url":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png","contentUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/SQLite-Window-Functions.png","width":512,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlitetutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQLite Window Functions"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlitetutorial.net\/#website","url":"https:\/\/www.sqlitetutorial.net\/","name":"SQLite Tutorial","description":"A Step-by-step SQLite Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlitetutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427","name":"admin"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/1659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/comments?post=1659"}],"version-history":[{"count":1,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/1659\/revisions"}],"predecessor-version":[{"id":3712,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/1659\/revisions\/3712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/media\/1688"}],"wp:attachment":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/media?parent=1659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}