{"id":1251,"date":"2019-02-21T09:05:52","date_gmt":"2019-02-21T02:05:52","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=1251"},"modified":"2020-07-11T04:06:15","modified_gmt":"2020-07-10T21:06:15","slug":"sql-server-ntile-function","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/","title":{"rendered":"SQL Server NTILE Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL Server <code>NTILE()<\/code> function to distribute rows of an ordered partition into a specified number of buckets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-sql-server-ntile-function'>Introduction to SQL Server NTILE() function <a href=\"#introduction-to-sql-server-ntile-function\" class=\"anchor\" id=\"introduction-to-sql-server-ntile-function\" title=\"Anchor for Introduction to SQL Server &lt;code&gt;NTILE()&lt;\/code&gt; function\">#<\/a><\/h2>\n\n\n\n<p>The SQL Server <code>NTILE()<\/code> is a <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/\">window function<\/a> that distributes rows of an ordered partition 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    &#91;PARTITION BY partition_expression, ... ]\n    ORDER BY sort_expression &#91;ASC | DESC], ...\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 into which the rows are divided. The buckets can be an expression or <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-subquery\/\">subquery<\/a> that evaluates to a positive integer. It cannot be a window function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='partition-by-clause'>PARTITION BY <strong>clause<\/strong> <a href=\"#partition-by-clause\" class=\"anchor\" id=\"partition-by-clause\" title=\"Anchor for &lt;code&gt;PARTITION BY&lt;\/code&gt; &lt;strong&gt;clause&lt;\/strong&gt;\">#<\/a><\/h3>\n\n\n\n<p>The <code>PARTITION BY<\/code> clause distributes rows of a result set into partitions to which the <code>NTILE()<\/code> function is applied.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='order-by-clause'>ORDER BY clause <a href=\"#order-by-clause\" class=\"anchor\" id=\"order-by-clause\" title=\"Anchor for &lt;code&gt;ORDER BY&lt;\/code&gt; clause\">#<\/a><\/h3>\n\n\n\n<p>The <code>ORDER BY<\/code> clause specifies the logical order of rows in each partition to which the <code>NTILE()<\/code> is applied.<\/p>\n\n\n\n<p>If the number of rows is not divisible by the <code>buckets<\/code>, the <code>NTILE()<\/code> function returns 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> in the <code>OVER()<\/code> clause.<\/p>\n\n\n\n<p>On the other hand, if the total of rows is divisible by the <code>buckets<\/code>, the function divides evenly the rows among buckets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-ntile-function-illustration'>SQL Server NTILE() function illustration <a href=\"#sql-server-ntile-function-illustration\" class=\"anchor\" id=\"sql-server-ntile-function-illustration\" title=\"Anchor for SQL Server &lt;code&gt;NTILE()&lt;\/code&gt; function illustration\">#<\/a><\/h2>\n\n\n\n<p>The following statement <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-create-table\/\">creates a new table<\/a> named <code>ntile_demo<\/code> that stores 10 integers:<\/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> sales.ntile_demo (\n\tv <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> sales.ntile_demo(v) \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> sales.ntile_demo;\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>This statement uses the <code>NTILE()<\/code> function to divide ten rows into three groups:<\/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\tv, \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> v\n\t) buckets\n<span class=\"hljs-keyword\">FROM<\/span> \n\tsales.ntile_demo;\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>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"138\" height=\"318\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.png\" alt=\"SQL Server NTILE Function\" class=\"wp-image-1252\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.png 138w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-130x300.png 130w\" sizes=\"auto, (max-width: 138px) 100vw, 138px\" \/><\/figure>\n\n\n\n<p>As clearly shown in the output, the first group has four rows and the other two groups have three rows.<\/p>\n\n\n\n<p>The following statement uses the <code>NTILE()<\/code> function to distribute rows into five 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\tv, \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> v\n\t) buckets\n<span class=\"hljs-keyword\">FROM<\/span> \n\tsales.ntile_demo;\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<p>The output is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"141\" height=\"320\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-with-5-groups.png\" alt=\"SQL Server NTILE Function with 5 groups\" class=\"wp-image-1253\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-with-5-groups.png 141w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-with-5-groups-132x300.png 132w\" sizes=\"auto, (max-width: 141px) 100vw, 141px\" \/><\/figure>\n\n\n\n<p>As you can see, the output has five groups with the same number of rows in each.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-ntile-function-examples'>SQL Server NTILE() function examples <a href=\"#sql-server-ntile-function-examples\" class=\"anchor\" id=\"sql-server-ntile-function-examples\" title=\"Anchor for SQL Server &lt;code&gt;NTILE()&lt;\/code&gt; function examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s create a view to demonstrate the <code>NTILE()<\/code> function.<\/p>\n\n\n\n<p>The following statement <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-views\/sql-server-create-view\/\">creates a view<\/a> that returns the net sales in 2017 by months.<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">VIEW<\/span> sales.vw_netsales_2017 <span class=\"hljs-keyword\">AS<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span> \n\tc.category_name,\n\t<span class=\"hljs-keyword\">DATENAME<\/span>(<span class=\"hljs-keyword\">month<\/span>, o.shipped_date) <span class=\"hljs-keyword\">month<\/span>, \n\t<span class=\"hljs-keyword\">CONVERT<\/span>(<span class=\"hljs-built_in\">DEC<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">0<\/span>), <span class=\"hljs-keyword\">SUM<\/span>(i.list_price * quantity * (<span class=\"hljs-number\">1<\/span> - discount))) net_sales\n<span class=\"hljs-keyword\">FROM<\/span> \n\tsales.orders o\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> sales.order_items i <span class=\"hljs-keyword\">ON<\/span> i.order_id = o.order_id\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> production.products p <span class=\"hljs-keyword\">on<\/span> p.product_id = i.product_id\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> production.categories c <span class=\"hljs-keyword\">on<\/span> c.category_id = p.category_id\n<span class=\"hljs-keyword\">WHERE<\/span> \n\t<span class=\"hljs-keyword\">YEAR<\/span>(shipped_date) = <span class=\"hljs-number\">2017<\/span>\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span>\n\tc.category_name,\n\t<span class=\"hljs-keyword\">DATENAME<\/span>(<span class=\"hljs-keyword\">month<\/span>, o.shipped_date);\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<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">SELECT<\/span> \n    <span class=\"hljs-selector-tag\">category_name<\/span>, \n    <span class=\"hljs-selector-tag\">month<\/span>,\n    <span class=\"hljs-selector-tag\">net_sales<\/span> \n<span class=\"hljs-selector-tag\">FROM<\/span> \n   <span class=\"hljs-selector-tag\">sales<\/span><span class=\"hljs-selector-class\">.vw_netsales_2017<\/span> \n<span class=\"hljs-selector-tag\">ORDER<\/span> <span class=\"hljs-selector-tag\">BY<\/span> \n   <span class=\"hljs-selector-tag\">category_name<\/span>, \n   <span class=\"hljs-selector-tag\">net_sales<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here is the result:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"223\" height=\"327\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-sample-view.png\" alt=\"SQL Server NTILE sample view\" class=\"wp-image-1325\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-sample-view.png 223w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-sample-view-205x300.png 205w\" sizes=\"auto, (max-width: 223px) 100vw, 223px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='using-sql-server-ntile-function-over-a-query-result-set-example'>Using SQL Server NTILE() function over a query result set example <a href=\"#using-sql-server-ntile-function-over-a-query-result-set-example\" class=\"anchor\" id=\"using-sql-server-ntile-function-over-a-query-result-set-example\" title=\"Anchor for Using SQL Server &lt;code&gt;NTILE()&lt;\/code&gt; function over a query result set example\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the <code>NTILE()<\/code> function to distribute the months to 4 buckets based on net sales:<\/p>\n\n\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\"><span class=\"hljs-keyword\">WITH<\/span> cte_by_month <span class=\"hljs-keyword\">AS<\/span>(\n\t<span class=\"hljs-keyword\">SELECT<\/span>\n\t\t<span class=\"hljs-keyword\">month<\/span>, \n\t\t<span class=\"hljs-keyword\">SUM<\/span>(net_sales) net_sales\n\t<span class=\"hljs-keyword\">FROM<\/span> \n\t\tsales.vw_netsales_2017\n\t<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span> \n\t\t<span class=\"hljs-keyword\">month<\/span>\n)\n<span class=\"hljs-keyword\">SELECT<\/span>\n\t<span class=\"hljs-keyword\">month<\/span>, \n\t<span class=\"hljs-keyword\">FORMAT<\/span>(net_sales,<span class=\"hljs-string\">'C'<\/span>,<span class=\"hljs-string\">'en-US'<\/span>) net_sales,\n\tNTILE(<span class=\"hljs-number\">4<\/span>) <span class=\"hljs-keyword\">OVER<\/span>(\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> net_sales <span class=\"hljs-keyword\">DESC<\/span>\n\t) net_sales_group\n<span class=\"hljs-keyword\">FROM<\/span> \n\tcte_by_month;\n<\/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>\n\n\n<p>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"322\" height=\"323\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Result-Set.png\" alt=\"SQL Server NTILE Function Over Result Set\" class=\"wp-image-1255\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Result-Set.png 322w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Result-Set-200x200.png 200w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Result-Set-300x300.png 300w\" sizes=\"auto, (max-width: 322px) 100vw, 322px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='using-sql-server-ntile-function-over-partitions-example'>Using SQL Server NTILE() function over partitions example <a href=\"#using-sql-server-ntile-function-over-partitions-example\" class=\"anchor\" id=\"using-sql-server-ntile-function-over-partitions-example\" title=\"Anchor for Using SQL Server &lt;code&gt;NTILE()&lt;\/code&gt; function over partitions example\">#<\/a><\/h3>\n\n\n\n<p>This example uses the <code>NTILE()<\/code> function to divide the net sales by month into 4 groups for each product category:<\/p>\n\n\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\"><span class=\"hljs-keyword\">SELECT<\/span>\n\tcategory_name,\n\t<span class=\"hljs-keyword\">month<\/span>, \n\t<span class=\"hljs-keyword\">FORMAT<\/span>(net_sales,<span class=\"hljs-string\">'C'<\/span>,<span class=\"hljs-string\">'en-US'<\/span>) net_sales,\n\tNTILE(<span class=\"hljs-number\">4<\/span>) <span class=\"hljs-keyword\">OVER<\/span>(\n\t\t<span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> category_name\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> net_sales <span class=\"hljs-keyword\">DESC<\/span>\n\t) net_sales_group\n<span class=\"hljs-keyword\">FROM<\/span> \n\tsales.vw_netsales_2017;\n<\/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>\n\n\n<p>The following picture shows the partial output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"490\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Partition-Example.png\" alt=\"SQL Server NTILE Function Over Partition Example\" class=\"wp-image-1256\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Partition-Example.png 353w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function-Over-Partition-Example-216x300.png 216w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/figure>\n\n\n\n<p>In this tutorial, you have learned how to use the SQL Server <code>NTILE()<\/code> function to distribute rows of an ordered partition into a specified number of buckets.<\/p>\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=\"1251\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/\"\n\t\t\t\tdata-post-title=\"SQL Server 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=\"1251\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/\"\n\t\t\t\tdata-post-title=\"SQL Server 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>In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition into a specified number of buckets.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1249,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1251","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>SQL Server NTILE() Function Explained By Practical Examples<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition 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.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server NTILE() Function Explained By Practical Examples\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition into a specified number of buckets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-10T21:06:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.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.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/\",\"name\":\"SQL Server NTILE() Function Explained By Practical Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-NTILE-Function.png\",\"datePublished\":\"2019-02-21T02:05:52+00:00\",\"dateModified\":\"2020-07-10T21:06:15+00:00\",\"description\":\"In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition into a specified number of buckets.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-NTILE-Function.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-NTILE-Function.png\",\"width\":138,\"height\":318,\"caption\":\"SQL Server NTILE Function\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/sql-server-ntile-function\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Window Functions\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-window-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server NTILE Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?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 Server NTILE() Function Explained By Practical Examples","description":"In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition 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.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server NTILE() Function Explained By Practical Examples","og_description":"In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition into a specified number of buckets.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2020-07-10T21:06:15+00:00","og_image":[{"url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/","name":"SQL Server NTILE() Function Explained By Practical Examples","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.png","datePublished":"2019-02-21T02:05:52+00:00","dateModified":"2020-07-10T21:06:15+00:00","description":"In this tutorial, you will learn how to use the SQL Server NTILE() function to distribute rows of an ordered partition into a specified number of buckets.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/#primaryimage","url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.png","contentUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-NTILE-Function.png","width":138,"height":318,"caption":"SQL Server NTILE Function"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-ntile-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Window Functions","item":"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/"},{"@type":"ListItem","position":3,"name":"SQL Server NTILE Function"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=1251"}],"version-history":[{"count":2,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1251\/revisions"}],"predecessor-version":[{"id":2667,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1251\/revisions\/2667"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1249"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}