{"id":1746,"date":"2018-09-08T18:56:03","date_gmt":"2018-09-09T01:56:03","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=1746"},"modified":"2025-01-20T09:15:05","modified_gmt":"2025-01-20T16:15:05","slug":"sql-ntile","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/","title":{"rendered":"SQL NTILE Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL <code>NTILE()<\/code> function to break a result set into a specified number of buckets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='an-overview-of-sql-ntile-function'>An Overview of SQL NTILE() function <a href=\"#an-overview-of-sql-ntile-function\" class=\"anchor\" id=\"an-overview-of-sql-ntile-function\" title=\"Anchor for An Overview of SQL NTILE() function\">#<\/a><\/h2>\n\n\n\n<p>The SQL <code>NTILE()<\/code> is a <a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\">window function<\/a> that allows you to break the result set into a specified number of approximately equal groups, or buckets. It assigns each group a bucket number starting from one. For each row in a group, the <code>NTILE()<\/code> function assigns a bucket number representing the group to which the row belongs.<\/p>\n\n\n\n<p>The syntax of the <code>NTILE()<\/code> function is as follows:<\/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\">NTILE(buckets) OVER ( \n\tPARTITION BY expr1, expr2,...\n\tORDER BY expr1 &#91;ASC|DESC], expr2 ...\n)\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>Let&#8217;s examine the syntax in detail:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='buckets'>buckets <a href=\"#buckets\" class=\"anchor\" id=\"buckets\" title=\"Anchor for &lt;code&gt;buckets&lt;\/code&gt;\">#<\/a><\/h3>\n\n\n\n<p>The number of buckets, which is a literal positive integer number or an expression that evaluates to a positive integer number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='partition-by'>PARTITION BY <a href=\"#partition-by\" class=\"anchor\" id=\"partition-by\" title=\"Anchor for &lt;code&gt;PARTITION BY&lt;\/code&gt;\">#<\/a><\/h3>\n\n\n\n<p>The <code>PARITITION BY<\/code> clause divides the result set returned from the <code>FROM<\/code> clause into partitions to which the <code>NTILE()<\/code> function is applied.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='order-by'>ORDER BY <a href=\"#order-by\" class=\"anchor\" id=\"order-by\" title=\"Anchor for &lt;code&gt;ORDER BY&lt;\/code&gt;\">#<\/a><\/h3>\n\n\n\n<p>The <code>ORDER BY<\/code> clause specifies the order of rows in each partition to which the <code>NTILE()<\/code> is applied.<\/p>\n\n\n\n<p>Notice that if the number of rows is not divisible by <code>buckets<\/code>, the <code>NTILE()<\/code> function results in groups of two sizes with the difference by one. The larger groups always come before the smaller group in the order specified by the <code>ORDER BY<\/code> clause.<\/p>\n\n\n\n<p>In case the total of rows is divisible by <code>buckets<\/code>, the rows are divided evenly among groups.<\/p>\n\n\n\n<p>The following statement creates a new table named <code>t<\/code> that stores 10 integers from one to ten:<\/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\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> t (\n\t<span class=\"hljs-keyword\">col<\/span> <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);\n\t\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> t(<span class=\"hljs-keyword\">col<\/span>) \n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-number\">1<\/span>),(<span class=\"hljs-number\">2<\/span>),(<span class=\"hljs-number\">3<\/span>),(<span class=\"hljs-number\">4<\/span>),(<span class=\"hljs-number\">5<\/span>),(<span class=\"hljs-number\">6<\/span>),(<span class=\"hljs-number\">7<\/span>),(<span class=\"hljs-number\">8<\/span>),(<span class=\"hljs-number\">9<\/span>),(<span class=\"hljs-number\">10<\/span>);\n\t\n\t\n<span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> t;\n<\/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>If you use the <code>NTILE()<\/code> function to divide ten rows into three groups, you will have the first group with four rows and other two groups with three rows.<\/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\">SELECT<\/span> \n\t<span class=\"hljs-keyword\">col<\/span>, \n\tNTILE (<span class=\"hljs-number\">3<\/span>) <span class=\"hljs-keyword\">OVER<\/span> (\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">col<\/span>\n\t) buckets\n<span class=\"hljs-keyword\">FROM<\/span> \n\tt;\n<\/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 following shows the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"119\" height=\"221\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png\" alt=\"SQL NTILE Function - buckets with different sizes\" class=\"wp-image-1747\"\/><\/figure>\n\n\n\n<p>As clearly shown in the output, the first group has four rows while the other groups have three rows.<\/p>\n\n\n\n<p>The following statement uses two instead of three buckets:<\/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\">SELECT<\/span> \n\t<span class=\"hljs-keyword\">col<\/span>, \n\tNTILE (<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">OVER<\/span> (\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">col<\/span>\n\t) buckets\n<span class=\"hljs-keyword\">FROM<\/span> \n\tt;\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>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"121\" height=\"221\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-same-sizes.png\" alt=\"\" class=\"wp-image-1748\"\/><\/figure>\n\n\n\n<p>Now, we have two groups which have the same number of rows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-ntile-function-examples'>SQL NTILE() function examples <a href=\"#sql-ntile-function-examples\" class=\"anchor\" id=\"sql-ntile-function-examples\" title=\"Anchor for SQL NTILE() function examples\">#<\/a><\/h2>\n\n\n\n<p>See the following <code>employees<\/code> table from the sample database:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='using-sql-ntile-function-over-the-result-set-example'>Using SQL NTILE() function over the result set example <a href=\"#using-sql-ntile-function-over-the-result-set-example\" class=\"anchor\" id=\"using-sql-ntile-function-over-the-result-set-example\" title=\"Anchor for Using SQL NTILE() function over the result set example\">#<\/a><\/h3>\n\n\n\n<p>The following statement uses the <code>NTILE()<\/code> function to divide the employees into five buckets based on their salaries:<\/p>\n\n\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\"><span class=\"hljs-keyword\">SELECT<\/span>\n\tfirst_name, \n\tlast_name, \n\tsalary,\n\tNTILE(<span class=\"hljs-number\">5<\/span>) <span class=\"hljs-keyword\">OVER<\/span> (\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> salary <span class=\"hljs-keyword\">DESC<\/span>\n\t) salary_group\n<span class=\"hljs-keyword\">FROM<\/span> \n\temployees;\n<\/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>\n\n\n<p>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"642\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-over-result-set-example.png\" alt=\"SQL NTILE function over result set example\" class=\"wp-image-1750\" title=\"SQL NTILE function over result set example\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-over-result-set-example.png 302w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-over-result-set-example-141x300.png 141w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='using-sql-ntile-function-over-partition-example'>Using SQL NTILE() function over partition example <a href=\"#using-sql-ntile-function-over-partition-example\" class=\"anchor\" id=\"using-sql-ntile-function-over-partition-example\" title=\"Anchor for Using SQL NTILE() function over partition example\">#<\/a><\/h3>\n\n\n\n<p>The following statement breaks the employees in each department into two groups:<\/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\tfirst_name, \n\tlast_name, \n\tdepartment_name,\n\tsalary,\n\tNTILE(<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">OVER<\/span> (\n\t\t<span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> department_name\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> salary\n\t) salary_group\n<span class=\"hljs-keyword\">FROM<\/span> \n\temployees e\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments d\n\t<span class=\"hljs-keyword\">ON<\/span> d.department_id = e.department_id;\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>\n\n\n<p>The following shows the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"413\" height=\"640\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-over-paritition-example.png\" alt=\"SQL NTILE function over partition example\" class=\"wp-image-1749\" title=\"SQL NTILE function over partition example\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-over-paritition-example.png 413w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-over-paritition-example-194x300.png 194w\" sizes=\"auto, (max-width: 413px) 100vw, 413px\" \/><\/figure>\n\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the <code>PARTITION BY<\/code> clause divided the employees by department names into partitions.<\/li>\n\n\n\n<li>Then, the <code>ORDER BY<\/code> clause sorted the employees in each partition by salary.<\/li>\n\n\n\n<li>Finally, the <code>NTILE()<\/code> function assigned each row in each partition a bucket number. It reset the bucket number whenever the department changes.<\/li>\n<\/ul>\n\n\n\n<p>In this tutorial, you have learned how to use the SQL <code>NTILE()<\/code> function to break the result set into a specified number of buckets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='databases'>Databases <a href=\"#databases\" class=\"anchor\" id=\"databases\" title=\"Anchor for Databases\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-ntile\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL NTILE function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/oracle-analytic-functions\/oracle-ntile\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oracle NTILE function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server NTILE function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-ntile-function\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL NTILE function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-ntile\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQLite NTILE function<\/a><\/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=\"1746\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/\"\n\t\t\t\tdata-post-title=\"SQL NTILE 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=\"1746\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/\"\n\t\t\t\tdata-post-title=\"SQL NTILE 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 SQL NTILE() function to break a result set into a specified number of buckets.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1707,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1746","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 NTILE Function<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL NTILE function to break a result set into a specified number of buckets.\" \/>\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\/sql-ntile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL NTILE Function\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL NTILE function to break a result set into a specified number of buckets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-20T16:15:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png\" \/>\n\t<meta property=\"og:image:width\" content=\"119\" \/>\n\t<meta property=\"og:image:height\" content=\"221\" \/>\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\/sql-ntile\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/\",\"name\":\"SQL NTILE Function\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png\",\"datePublished\":\"2018-09-09T01:56:03+00:00\",\"dateModified\":\"2025-01-20T16:15:05+00:00\",\"description\":\"This tutorial shows you how to use the SQL NTILE function to break a result set into a specified number of buckets.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#primaryimage\",\"url\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png\",\"contentUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png\",\"width\":119,\"height\":221,\"caption\":\"SQL NTILE Function - buckets with different sizes\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Window Functions\",\"item\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL NTILE Function\"}]},{\"@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 NTILE Function","description":"This tutorial shows you how to use the SQL NTILE function to break a result set into a specified number of buckets.","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\/sql-ntile\/","og_locale":"en_US","og_type":"article","og_title":"SQL NTILE Function","og_description":"This tutorial shows you how to use the SQL NTILE function to break a result set into a specified number of buckets.","og_url":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/","og_site_name":"SQL Tutorial","article_modified_time":"2025-01-20T16:15:05+00:00","og_image":[{"width":119,"height":221,"url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.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\/sql-ntile\/","url":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/","name":"SQL NTILE Function","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#primaryimage"},"image":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png","datePublished":"2018-09-09T01:56:03+00:00","dateModified":"2025-01-20T16:15:05+00:00","description":"This tutorial shows you how to use the SQL NTILE function to break a result set into a specified number of buckets.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#primaryimage","url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png","contentUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-NTILE-Function-buckets-with-different-sizes.png","width":119,"height":221,"caption":"SQL NTILE Function - buckets with different sizes"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-ntile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL Window Functions","item":"https:\/\/www.sqltutorial.org\/sql-window-functions\/"},{"@type":"ListItem","position":3,"name":"SQL NTILE Function"}]},{"@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\/1746","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=1746"}],"version-history":[{"count":0,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1746\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1707"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=1746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}