{"id":1707,"date":"2018-09-08T02:36:22","date_gmt":"2018-09-08T09:36:22","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=1707"},"modified":"2025-02-09T20:11:57","modified_gmt":"2025-02-10T03:11:57","slug":"sql-window-functions","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-window-functions\/","title":{"rendered":"SQL Window Functions"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you will learn about SQL window functions that solve complex query challenges easily.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='introduction-to-sql-window-functions'>Introduction to SQL Window Functions <a href=\"#introduction-to-sql-window-functions\" class=\"anchor\" id=\"introduction-to-sql-window-functions\" title=\"Anchor for Introduction to SQL Window Functions\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>The <a href=\"https:\/\/www.sqltutorial.org\/sql-aggregate-functions\/\">aggregate functions<\/a> perform calculations across rows and return a single output row.<\/p>\r\n\r\n\r\n\r\n<p>The following query uses the <code><a href=\"https:\/\/www.sqltutorial.org\/sql-aggregate-functions\/sql-sum\/\">SUM()<\/a><\/code> aggregate function to calculate the total salary of all employees in the company:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n  <span class=\"hljs-keyword\">SUM<\/span>(salary) total_salary\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIFNVTShzYWxhcnkpIHN1bV9zYWxhcnkgRlJPTSBlbXBsb3llZXM7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\"> total_salary\r\n--------------\r\n    322400.00<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The output indicates that query group rows from the \u00a0<code>employees<\/code> table\u00a0into a single row.<\/p>\r\n\r\n\r\n\r\n<p>Like an aggregate function, a window function operates on a set of rows. However, a window function does not group rows into a single row.<\/p>\r\n\r\n\r\n\r\n<p>For example, the following query uses the <code>SUM()<\/code> function as a window function:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n  first_name,\r\n  last_name,\r\n  salary,\r\n  <span class=\"hljs-keyword\">SUM<\/span>(salary) <span class=\"hljs-keyword\">OVER<\/span> () total_salary\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p><a href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIGZpcnN0X25hbWUsIGxhc3RfbmFtZSwgc2FsYXJ5LCBTVU0oc2FsYXJ5KSBPVkVSICgpIHRvdGFsX3NhbGFyeSBGUk9NIGVtcGxveWVlczs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<p>It returns the salary of each individual employee along with the total salary of all employees:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> first_name  |  last_name  |  salary  | sum_salary\r\n-------------+-------------+----------+------------\r\n Steven      | King        | 24000.00 |  322400.00\r\n Neena       | Kochhar     | 17000.00 |  322400.00\r\n Lex         | De Haan     | 17000.00 |  322400.00\r\n Alexander   | Hunold      |  9000.00 |  322400.00\r\n Bruce       | Ernst       |  6000.00 |  322400.00\r\n...<\/code><\/span><\/pre>\r\n\r\n\r\n<p>In this example, the <code>OVER()<\/code> clause makes the <code>SUM()<\/code> function a window function.<\/p>\r\n\r\n\r\n\r\n<p>The following picture illustrates the main difference between aggregate and window functions:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"288\" class=\"wp-image-1787\" title=\"SQL window functions\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png\" alt=\"sql window functions\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png 748w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions-300x116.png 300w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='sql-window-function-syntax'>SQL window function syntax <a href=\"#sql-window-function-syntax\" class=\"anchor\" id=\"sql-window-function-syntax\" title=\"Anchor for SQL window function syntax\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>Here&#8217;s the basic syntax of a window function:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">window_function_name ( expression ) OVER (\r\n    partition_clause\r\n    order_clause\r\n    frame_clause\r\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p><code>window_function_name<\/code><\/p>\r\n\r\n\r\n\r\n<p>The window function name, such as <code><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-row_number\/\">ROW_NUMBER()<\/a><\/code>, <code><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-rank\/\">RANK()<\/a><\/code>, and <code><a href=\"https:\/\/www.sqltutorial.org\/sql-aggregate-functions\/sql-sum\/\">SUM()<\/a><\/code>.<\/p>\r\n\r\n\r\n\r\n<p><code>expression<\/code><\/p>\r\n\r\n\r\n\r\n<p>The expression or column on which the window function operates.<\/p>\r\n\r\n\r\n\r\n<p><code>OVER<\/code> clause<\/p>\r\n\r\n\r\n\r\n<p>The <code>OVER<\/code> clause defines a window or a partition. The <code>OVER<\/code> clause consists of three clauses:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Partition By clause<\/li>\r\n\r\n\r\n\r\n<li>Order By clause<\/li>\r\n\r\n\r\n\r\n<li>Frame clause<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>The <a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-partition-by\/\">PARTITION BY<\/a> clause divides the rows into partitions to which the window function applies. It has the following syntax:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">PARTITION BY expr1, expr2, ...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>If you don&#8217;t use the <code>PARTITION BY<\/code> clause, the window function treats the whole result set as a single partition.<\/p>\r\n\r\n\r\n\r\n<p>The <code>ORDER BY<\/code> specifies the orders of rows in each partition:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">ORDER BY \r\n    sort_expression &#91;ASC | DESC]  &#91;NULL {FIRST| LAST}]\r\n    ,...\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>A frame is the subset of the current partition. To define the frame, you use one of the following syntaxes:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">{ RANGE | ROWS } frame_start\r\n{ RANGE | ROWS } BETWEEN frame_start AND frame_end  <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>where <code>frame_start<\/code> is one of the following options:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">N PRECEDING\r\nUNBOUNDED PRECEDING\r\nCURRENT ROW<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>and <code>frame_end<\/code> is one of the following options:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CURRENT ROW\r\nUNBOUNDED FOLLOWING\r\nN FOLLOWING<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The following picture illustrates a frame and its options:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"579\" height=\"408\" class=\"wp-image-1789\" title=\"SQL window function frame\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-function-frame.png\" alt=\"SQL window function frame\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-function-frame.png 579w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-function-frame-300x211.png 300w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/figure>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><code>UNBOUNDED PRECEDING<\/code>: the frame starts at the first row of the partition.<\/li>\r\n\r\n\r\n\r\n<li><code>N PRECEDING<\/code>: the frame starts at the nth row before the current row.<\/li>\r\n\r\n\r\n\r\n<li><code>CURRENT ROW<\/code>: means the current row that is being evaluated.<\/li>\r\n\r\n\r\n\r\n<li><code>UNBOUNDED FOLLOWING<\/code>: the frame ends at the final row in the partition.<\/li>\r\n\r\n\r\n\r\n<li><code>N FOLLOWING<\/code>: the frame ends at the Nh row after the current row.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>The <code>ROWS<\/code> or <code>RANGE<\/code> specifies the type of relationship between the current row and frame rows.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>\u00a0<code>ROWS<\/code>: the offsets of the current row and frame rows are row numbers.<\/li>\r\n\r\n\r\n\r\n<li>\u00a0<code>RANGE<\/code>: the offset of the current row and frame rows are row values.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='sql-window-function-types'>SQL window function types <a href=\"#sql-window-function-types\" class=\"anchor\" id=\"sql-window-function-types\" title=\"Anchor for SQL window function types\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>There are three types of window functions including value window functions, aggregation window functions, and ranking window functions.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='value-window-functions'>Value window functions <a href=\"#value-window-functions\" class=\"anchor\" id=\"value-window-functions\" title=\"Anchor for Value window functions\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-first_value\/\">FIRST_VALUE()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-lag\/\">LAG()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\">LAST_VALUE()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-lead\/\">LEAD()<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='ranking-window-functions'>Ranking window functions <a href=\"#ranking-window-functions\" class=\"anchor\" id=\"ranking-window-functions\" title=\"Anchor for Ranking window functions\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-cume_dist\/\">CUME_DIST()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-dense_rank\/\">DENSE_RANK()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/\">NTILE()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-percent_rank\/\">PERCENT_RANK()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-rank\/\">RANK()<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-row_number\/\">ROW_NUMBER()<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='aggregate-window-functions'>Aggregate window functions <a href=\"#aggregate-window-functions\" class=\"anchor\" id=\"aggregate-window-functions\" title=\"Anchor for Aggregate window functions\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>AVG()<\/li>\r\n\r\n\r\n\r\n<li>COUNT()<\/li>\r\n\r\n\r\n\r\n<li>MAX()<\/li>\r\n\r\n\r\n\r\n<li>MIN()<\/li>\r\n\r\n\r\n\r\n<li>SUM()<\/li>\r\n<\/ul>\r\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":67,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1707","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Window Functions<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.\" \/>\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.sqltutorial.org\/sql-window-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Window Functions\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-10T03:11:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png\" \/>\n\t<meta property=\"og:image:width\" content=\"748\" \/>\n\t<meta property=\"og:image:height\" content=\"288\" \/>\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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\",\"name\":\"SQL Window Functions\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png\",\"datePublished\":\"2018-09-08T09:36:22+00:00\",\"dateModified\":\"2025-02-10T03:11:57+00:00\",\"description\":\"This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/#primaryimage\",\"url\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png\",\"contentUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png\",\"width\":748,\"height\":288,\"caption\":\"sql window functions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Window Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqltutorial.org\/#website\",\"url\":\"https:\/\/www.sqltutorial.org\/\",\"name\":\"SQL Tutorial\",\"description\":\"An Interactive SQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqltutorial.org\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Window Functions","description":"This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.","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.sqltutorial.org\/sql-window-functions\/","og_locale":"en_US","og_type":"article","og_title":"SQL Window Functions","og_description":"This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.","og_url":"https:\/\/www.sqltutorial.org\/sql-window-functions\/","og_site_name":"SQL Tutorial","article_modified_time":"2025-02-10T03:11:57+00:00","og_image":[{"width":748,"height":288,"url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/","url":"https:\/\/www.sqltutorial.org\/sql-window-functions\/","name":"SQL Window Functions","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png","datePublished":"2018-09-08T09:36:22+00:00","dateModified":"2025-02-10T03:11:57+00:00","description":"This tutorial shows you how to use the SQL window functions to solve complex query challenges in easy ways.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-window-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/#primaryimage","url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png","contentUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/sql-window-functions.png","width":748,"height":288,"caption":"sql window functions"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL Window Functions"}]},{"@type":"WebSite","@id":"https:\/\/www.sqltutorial.org\/#website","url":"https:\/\/www.sqltutorial.org\/","name":"SQL Tutorial","description":"An Interactive SQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/comments?post=1707"}],"version-history":[{"count":0,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1707\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=1707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}