{"id":7079,"date":"2018-08-29T06:58:11","date_gmt":"2018-08-29T13:58:11","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=7079"},"modified":"2024-01-04T04:07:12","modified_gmt":"2024-01-04T11:07:12","slug":"mysql-percent_rank-function","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/","title":{"rendered":"MySQL PERCENT_RANK Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the MySQL <code>PERCENT_RANK()<\/code> function to calculate the percentile ranking of a row within a partition or result set.<\/p>\n\n\n\n<p>The <code>PERCENT_RANK()<\/code> is a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/\">window function<\/a> that calculates the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Percentile_rank\">percentile rank<\/a> of a row within a partition or result set.<\/p>\n\n\n\n<p>The following shows the syntax of the <code>PERCENT_RANK()<\/code> function:<\/p>\n\n\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\">PERCENT_RANK() OVER (\n  PARTITION BY partition_expression \n  ORDER BY \n    sort_expression &#91;ASC | DESC]\n)<\/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>\n\n\n<p>The <code>PERCENT_RANK()<\/code> function returns a number that ranges from zero to one.<\/p>\n\n\n\n<p>For a specified row, <code>PERCENT_RANK()<\/code> calculates the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-rank-function\/\">rank<\/a> of that row minus one, divided by 1 less than the number of rows in the evaluated partition or query result set:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">(rank - 1) \/ (total_rows - 1)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>\n\n\n<p>In this formula, <code>rank<\/code> is the rank of a specified row and <code>total_rows<\/code> is the number of rows being evaluated.<\/p>\n\n\n\n<p>The <code>PERCENT_RANK()<\/code> function always returns zero for the first row in a partition or result set. The repeated column values will receive the same <code>PERCENT_RANK()<\/code> value.<\/p>\n\n\n\n<p>Similar to other window functions, the <code>PARTITION BY<\/code> clause distributes the rows into partitions and the <code>ORDER BY<\/code> clause specifies the logical order of rows in each partition. The <code>PERCENT_RANK()<\/code> function is calculated for each ordered partition independently.<\/p>\n\n\n\n<p>Both <code>PARTITION BY<\/code> and <code>ORDER BY<\/code> clauses are optional. However, the <code>PERCENT_RANK()<\/code> is an order-sensitive function, therefore, you should always use the <code>ORDER BY<\/code> clause.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL PERCENT_RANK() function examples<\/h2>\n\n\n\n<p>Let&#8217;s create a new table named <code>productLineSales<\/code> based on the <code>orders<\/code>, <code>orderDetails<\/code>, and <code>products<\/code> tables from the <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>:<\/p>\n\n\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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> productLineSales\n<span class=\"hljs-keyword\">SELECT<\/span>\n    productLine,\n    <span class=\"hljs-keyword\">YEAR<\/span>(orderDate) orderYear,\n    quantityOrdered * priceEach orderValue\n<span class=\"hljs-keyword\">FROM<\/span>\n    orderDetails\n        <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span>\n    orders <span class=\"hljs-keyword\">USING<\/span> (orderNumber)\n        <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span>\n    products <span class=\"hljs-keyword\">USING<\/span> (productCode)\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    productLine ,\n    <span class=\"hljs-keyword\">YEAR<\/span>(orderDate), \n    orderValue;<\/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>\n\n\n<p>The <code>productLineSales<\/code> table stores the summary of the sales data including product line, order year, and order value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Using MySQL PERCENT_RANK() over the query result set<\/h3>\n\n\n\n<p>The following query finds the percentile rank of every product line by order values:<\/p>\n\n\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\"><span class=\"hljs-keyword\">WITH<\/span> t <span class=\"hljs-keyword\">AS<\/span> (\n    <span class=\"hljs-keyword\">SELECT<\/span>\n        productLine,\n        <span class=\"hljs-keyword\">SUM<\/span>(orderValue) orderValue\n    <span class=\"hljs-keyword\">FROM<\/span>\n        productLineSales\n    <span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span>\n        productLine\n)\n<span class=\"hljs-keyword\">SELECT<\/span>\n    productLine,\n    orderValue,\n    <span class=\"hljs-keyword\">ROUND<\/span>(\n       <span class=\"hljs-keyword\">PERCENT_RANK<\/span>() <span class=\"hljs-keyword\">OVER<\/span> (\n          <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> orderValue\n       )\n    ,<span class=\"hljs-number\">2<\/span>) percentile_rank\n<span class=\"hljs-keyword\">FROM<\/span>\n    t;<\/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>\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, we used a common table expression to summarize the order values by product lines.<\/li>\n\n\n\n<li>Second, we used the <code>PERCENT_RANK()<\/code> to calculate the percentile rank of the order value of each product. In addition, we used the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-math-functions\/mysql-round\/\">ROUND()<\/a><\/code> function to round the values to 2 decimals for a better representation.<\/li>\n<\/ul>\n\n\n\n<p>Here is the output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+------------------+------------+-----------------+\r\n| productLine      | orderValue | percentile_rank |\r\n+------------------+------------+-----------------+\r\n| Trains           |  <span class=\"hljs-number\">188532.92<\/span> |               <span class=\"hljs-number\">0<\/span> |\r\n| Ships            |  <span class=\"hljs-number\">661622.34<\/span> |            <span class=\"hljs-number\">0.17<\/span> |\r\n| Planes           |  <span class=\"hljs-number\">944295.37<\/span> |            <span class=\"hljs-number\">0.33<\/span> |\r\n| Trucks and Buses | <span class=\"hljs-number\">1014787.52<\/span> |             <span class=\"hljs-number\">0.5<\/span> |\r\n| Motorcycles      | <span class=\"hljs-number\">1114192.13<\/span> |            <span class=\"hljs-number\">0.67<\/span> |\r\n| Vintage Cars     | <span class=\"hljs-number\">1782234.23<\/span> |            <span class=\"hljs-number\">0.83<\/span> |\r\n| Classic Cars     | <span class=\"hljs-number\">3782065.50<\/span> |               <span class=\"hljs-number\">1<\/span> |\r\n+------------------+------------+-----------------+\r\n<span class=\"hljs-number\">7<\/span> rows <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here are some analyses from the output:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The order values of <code>Trains<\/code> were not better than any other product lines, which was represented with a zero.<\/li>\n\n\n\n<li>&nbsp;<code>Vintage Cars<\/code> performed better than 50% of other products.<\/li>\n\n\n\n<li>\u00a0<code>Classic Cars<\/code> performed better than any other product line so its percent rank is 1 or 100%<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2) Using MySQL PERCENT_RANK() over the partition<\/h3>\n\n\n\n<p>The following statement returns the percentile ranking of product lines by order values in each year:<\/p>\n\n\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\"><span class=\"hljs-keyword\">SELECT<\/span>\n    productLine,\n    orderYear,\n    orderValue,\n    <span class=\"hljs-keyword\">ROUND<\/span>(\n    <span class=\"hljs-keyword\">PERCENT_RANK<\/span>()\n    <span class=\"hljs-keyword\">OVER<\/span> (\n        <span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> orderYear\n        <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> orderValue\n    ),<span class=\"hljs-number\">2<\/span>) percentile_rank\n<span class=\"hljs-keyword\">FROM<\/span>\n    productLineSales;<\/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>\n\n\n<p>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"340\" height=\"437\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png\" alt=\"MySQL PERCENT_RANK function over partition example\" class=\"wp-image-7084\" title=\"MySQL PERCENT_RANK function over partition example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png 340w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1-156x200.png 156w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/figure>\n\n\n\n<p>In this example, we divided the order values of the product lines by order year. The <code>PERCENT_RANK()<\/code> then applied to each partition.<\/p>\n\n\n\n<p>For example, in 2003 <code>Vintage Cars<\/code>\u00a0performed better than 50% of other product lines while in 2004 Ships performed better than 50% of other products.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the MySQL <code>PERCENT_RANK()<\/code> function to calculate the percentile rank of a row within a partition or result set.<\/li>\n<\/ul>\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=\"7079\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/\"\n\t\t\t\tdata-post-title=\"MySQL PERCENT_RANK Function\"\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=\"7079\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/\"\n\t\t\t\tdata-post-title=\"MySQL PERCENT_RANK Function\"\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>This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":6941,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7079","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>MySQL PERCENT_RANK Function By Practical Examples<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.\" \/>\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.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL PERCENT_RANK Function By Practical Examples\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-04T11:07:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png\" \/>\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.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/\",\"name\":\"MySQL PERCENT_RANK Function By Practical Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-PERCENT_RANK-function-over-partition-example-1.png\",\"datePublished\":\"2018-08-29T13:58:11+00:00\",\"dateModified\":\"2024-01-04T11:07:12+00:00\",\"description\":\"This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-PERCENT_RANK-function-over-partition-example-1.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-PERCENT_RANK-function-over-partition-example-1.png\",\"width\":340,\"height\":437,\"caption\":\"MySQL PERCENT_RANK function over partition example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-percent_rank-function\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Window Functions\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL PERCENT_RANK Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.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":"MySQL PERCENT_RANK Function By Practical Examples","description":"This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.","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.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/","og_locale":"en_US","og_type":"article","og_title":"MySQL PERCENT_RANK Function By Practical Examples","og_description":"This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-04T11:07:12+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/","url":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/","name":"MySQL PERCENT_RANK Function By Practical Examples","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png","datePublished":"2018-08-29T13:58:11+00:00","dateModified":"2024-01-04T11:07:12+00:00","description":"This tutorial shows you how to use the MySQL PERCENT_RANK() function to calculate the percentile rank of a row within a partition or result set.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-PERCENT_RANK-function-over-partition-example-1.png","width":340,"height":437,"caption":"MySQL PERCENT_RANK function over partition example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-percent_rank-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Window Functions","item":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/"},{"@type":"ListItem","position":3,"name":"MySQL PERCENT_RANK Function"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=7079"}],"version-history":[{"count":1,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7079\/revisions"}],"predecessor-version":[{"id":14178,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7079\/revisions\/14178"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6941"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=7079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}