{"id":1072,"date":"2024-12-19T09:42:28","date_gmt":"2024-12-19T02:42:28","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=1072"},"modified":"2024-12-25T08:41:33","modified_gmt":"2024-12-25T01:41:33","slug":"postgresql-window-functions","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/","title":{"rendered":"PostgreSQL Window Functions"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='getting-started-with-postgresql-window-functions'>Getting Started with PostgreSQL Window Functions <a href=\"#getting-started-with-postgresql-window-functions\" class=\"anchor\" id=\"getting-started-with-postgresql-window-functions\" title=\"Anchor for Getting Started with PostgreSQL Window Functions\">#<\/a><\/h2>\n\n\n\n<p>In PostgreSQL, a window function allows you to calculate across a set of rows related to the current row.<\/p>\n\n\n\n<p>If it sounds confusing to you, let&#8217;s take an example to make the concept more clear.<\/p>\n\n\n\n<p>Suppose you want to retrieve the product name, price, and highest price from the <code>products<\/code> table:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"159\" height=\"254\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png\" alt=\"\" class=\"wp-image-1051\"\/><\/figure>\n\n\n\n<p>If you use the <code>MAX<\/code> aggregate function, you&#8217;ll get a single row:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  MAX(price)\n<span class=\"hljs-keyword\">FROM<\/span>\n  products;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIE1BWChwcmljZSkgRlJPTSBwcm9kdWN0czs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">   max\n<span class=\"hljs-comment\">---------<\/span>\n <span class=\"hljs-number\">2999.99<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To get the product and price for each row together with the max price, you can use the <code>MAX<\/code> window function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  price,\n  MAX(price) <span class=\"hljs-keyword\">OVER<\/span> ()\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n  price <span class=\"hljs-keyword\">DESC<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgcHJpY2UsIE1BWChwcmljZSkgT1ZFUiAoKSBGUk9NIHByb2R1Y3RzIE9SREVSIEJZIHByaWNlIERFU0M7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">        product_name        |  price  |   max\n<span class=\"hljs-comment\">----------------------------+---------+---------<\/span>\n Samsung QN900C Neo QLED    | <span class=\"hljs-number\">2999.99<\/span> | <span class=\"hljs-number\">2999.99<\/span>\n LG G3 OLED                 | <span class=\"hljs-number\">2499.99<\/span> | <span class=\"hljs-number\">2999.99<\/span>\n Sony Bravia XR A95K        | <span class=\"hljs-number\">2499.99<\/span> | <span class=\"hljs-number\">2999.99<\/span>\n LG OLED TV C3              | <span class=\"hljs-number\">1999.99<\/span> | <span class=\"hljs-number\">2999.99<\/span>\n Samsung Galaxy Z Fold <span class=\"hljs-number\">5<\/span>    | <span class=\"hljs-number\">1799.99<\/span> | <span class=\"hljs-number\">2999.99<\/span>\n Lenovo ThinkPad X1 Carbon  | <span class=\"hljs-number\">1599.99<\/span> | <span class=\"hljs-number\">2999.99<\/span>\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the <code>OVER<\/code> clause makes the <code>MAX<\/code> function a window function.<\/p>\n\n\n\n<p>The <code>MAX<\/code> window function returns the maximum price for each row in the products table.<\/p>\n\n\n\n<p>Unlike the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-aggregate-functions\/postgresql-max\/\">MAX<\/a><\/code> aggregate function, the <code>MAX<\/code> window function does not group rows but retains individual rows.<\/p>\n\n\n\n<p>In practice, you&#8217;ll find the window functions helpful for queries like calculating running total, ranking, and moving averages.<\/p>\n\n\n\n<p class=\"note\">Note that <em>analytic function<\/em> is another term often used to refer to window function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-window-function-syntax'>PostgreSQL Window Function Syntax <a href=\"#postgresql-window-function-syntax\" class=\"anchor\" id=\"postgresql-window-function-syntax\" title=\"Anchor for PostgreSQL Window Function Syntax\">#<\/a><\/h2>\n\n\n\n<p>Here&#8217;s the basic syntax for a window function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">function_name (expression) <span class=\"hljs-keyword\">OVER<\/span> (\n    &#91;<span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> expression_list]\n    &#91;<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> expression_list]\n    &#91;frame_clause]\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>function_name<\/code>: The window function name such as <code>MAX<\/code>.<\/li>\n\n\n\n<li><code>expression<\/code>: The column or expression you want the window function to calculate.<\/li>\n\n\n\n<li><code>PARTITION BY<\/code>: This optional clause groups the rows into partitions where the window function applies.<\/li>\n\n\n\n<li><code>ORDER BY<\/code>: This clause defines the order of rows within each partition. Note that it differs from the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-order-by\/\">ORDER BY<\/a><\/code> clause in the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-select\/\">SELECT<\/a><\/code> statement.<\/li>\n\n\n\n<li><code>frame_clause<\/code>: This clause defines the subset of rows within the partition for the window function to consider.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-window-function-list'>PostgreSQL Window Function List <a href=\"#postgresql-window-function-list\" class=\"anchor\" id=\"postgresql-window-function-list\" title=\"Anchor for PostgreSQL Window Function List\">#<\/a><\/h2>\n\n\n\n<p>There are three kinds of window function in PostgreSQL:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\" id='ranking-window-functions'>Section 1. Ranking Window Functions <a href=\"#ranking-window-functions\" class=\"anchor\" id=\"ranking-window-functions\" title=\"Anchor for Section 1. Ranking Window Functions\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-cume_dist\/\">CUME_DIST<\/a>: Returns the cumulative distribution of a value in a set.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-dense_rank\/\">DENSE_RANK<\/a>: Returns the rank of the current row without gaps.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-ntile\/\">NTILE<\/a>: Divides rows within into into roughly equal-sized buckets and assigns a tile number to each row.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-rank\/\">RANK<\/a>: Returns the ranks of the current row with gaps.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-row_number\/\">ROW_NUMBER<\/a>: Returns the number of the current row starting from 1.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-percent_rank\/\">PERCENT_RANK<\/a>: Returns relative rank of each row in a set.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\" id='value-window-functions'>Section 2. Value Window Functions <a href=\"#value-window-functions\" class=\"anchor\" id=\"value-window-functions\" title=\"Anchor for Section 2. Value Window Functions\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-first_value\/\">FIRST_VALUE<\/a>: Returns the value of the first row in each partition.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-last_value\/\">LAST_VALUE<\/a>: Returns the value of the last row in each partition.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-lag\/\">LAG<\/a>: Returns a value from a subsequent row, helpful for forward-looking comparisons.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-lead\/\">LEAD<\/a>: Returns a value from a preceding row, helpful for backward-looking comparisons.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-nth_value\/\">NTH_VALUE<\/a>: Returns the value of the n<sup>th<\/sup> row within a window frame, helpful for accessing specific rows.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\" id='aggregate-window-functions'>Section 3. Aggregate Window Functions <a href=\"#aggregate-window-functions\" class=\"anchor\" id=\"aggregate-window-functions\" title=\"Anchor for Section 3. Aggregate Window Functions\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-min\/\">MIN<\/a>: Returns the minimum value in a set of values within a partition.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-max-window-function\/\">MAX<\/a>: Returns the maximum value in a set of values within a partition.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-avg-window-function\/\">AVG<\/a>: Returns the average value in a set of values within a partition.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-count-window-function\/\">COUNT<\/a>: Returns the number of values or rows within a partition.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-sum-window-function\/\">SUM<\/a>: Returns the sum of values within a partition, useful for calculating the total along with the current row or running total.<\/li>\n<\/ul>\n<\/div><\/div>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1072\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Window Functions\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1072\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Window Functions\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: in this tutorial, you&#8217;ll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries. Getting Started with PostgreSQL Window Functions # In PostgreSQL, a window function allows you to calculate across a set of rows related to the current row. If it sounds confusing to you, let&#8217;s take an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1072","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL Window Functions<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.\" \/>\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.pgtutorial.com\/postgresql-window-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL Window Functions\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-25T01:41:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png\" \/>\n\t<meta property=\"og:image:width\" content=\"159\" \/>\n\t<meta property=\"og:image:height\" content=\"254\" \/>\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.pgtutorial.com\\\/postgresql-window-functions\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/\",\"name\":\"PostgreSQL Window Functions\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"datePublished\":\"2024-12-19T02:42:28+00:00\",\"dateModified\":\"2024-12-25T01:41:33+00:00\",\"description\":\"In this tutorial, you'll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"width\":159,\"height\":254,\"caption\":\"PostgreSQL Expression Index\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-window-functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Window Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?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":"PostgreSQL Window Functions","description":"In this tutorial, you'll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.","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.pgtutorial.com\/postgresql-window-functions\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Window Functions","og_description":"In this tutorial, you'll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2024-12-25T01:41:33+00:00","og_image":[{"width":159,"height":254,"url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.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.pgtutorial.com\/postgresql-window-functions\/","url":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/","name":"PostgreSQL Window Functions","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","datePublished":"2024-12-19T02:42:28+00:00","dateModified":"2024-12-25T01:41:33+00:00","description":"In this tutorial, you'll learn about PostgreSQL window functions and how to use them effectively to construct powerful queries.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-window-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","width":159,"height":254,"caption":"PostgreSQL Expression Index"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Window Functions"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=1072"}],"version-history":[{"count":20,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1072\/revisions"}],"predecessor-version":[{"id":1266,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1072\/revisions\/1266"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}