{"id":1020,"date":"2018-10-21T17:49:09","date_gmt":"2018-10-21T10:49:09","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=1020"},"modified":"2024-04-04T07:44:51","modified_gmt":"2024-04-04T00:44:51","slug":"sql-server-avg","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/","title":{"rendered":"SQL Server AVG() Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL Server <code>AVG()<\/code> function to calculate the average value from a group of values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-sql-server-avg-function'>Introduction to SQL Server AVG() function <a href=\"#introduction-to-sql-server-avg-function\" class=\"anchor\" id=\"introduction-to-sql-server-avg-function\" title=\"Anchor for Introduction to SQL Server AVG() function\">#<\/a><\/h2>\n\n\n\n<p>SQL Server <code>AVG()<\/code> function is an <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/\">aggregate function<\/a> that returns the average value of a group.<\/p>\n\n\n\n<p>The following illustrates the syntax of the <code>AVG()<\/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\">AVG(&#91;ALL | DISTINCT] expression)<\/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>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ALL<\/code> instructs the <code>AVG()<\/code> function to take all values for calculation. <code>ALL<\/code> is used by default.<\/li>\n\n\n\n<li><code>DISTINCT<\/code> instructs the <code>AVG()<\/code> function to operate only on unique values.<\/li>\n\n\n\n<li><code>expression<\/code> is a valid expression that returns a numeric value.<\/li>\n<\/ul>\n\n\n\n<p>The <code>AVG()<\/code> function ignores <code>NULL<\/code> values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-avg-function-all-vs-distinct'>SQL Server AVG() function: ALL vs. DISTINCT <a href=\"#sql-server-avg-function-all-vs-distinct\" class=\"anchor\" id=\"sql-server-avg-function-all-vs-distinct\" title=\"Anchor for SQL Server AVG() function: ALL vs. DISTINCT\">#<\/a><\/h2>\n\n\n\n<p>The following statements <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-create-table\/\">create a new table<\/a>, <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-insert\/\">insert<\/a> some values into the table, and <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select\/\">query<\/a> data against it:<\/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    val <span class=\"hljs-built_in\">dec<\/span>(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>)\n);\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> t(val) \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\">4<\/span>),(<span class=\"hljs-number\">5<\/span>),(<span class=\"hljs-number\">5<\/span>),(<span class=\"hljs-number\">6<\/span>);\n\n<span class=\"hljs-keyword\">SELECT<\/span> val <span class=\"hljs-keyword\">FROM<\/span> t;<\/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>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">val<\/span>\n<span class=\"hljs-selector-tag\">----<\/span>\n1<span class=\"hljs-selector-class\">.00<\/span>\n2<span class=\"hljs-selector-class\">.00<\/span>\n3<span class=\"hljs-selector-class\">.00<\/span>\n4<span class=\"hljs-selector-class\">.00<\/span>\n4<span class=\"hljs-selector-class\">.00<\/span>\n5<span class=\"hljs-selector-class\">.00<\/span>\n5<span class=\"hljs-selector-class\">.00<\/span>\n6<span class=\"hljs-selector-class\">.00<\/span>\n(8 <span class=\"hljs-selector-tag\">rows<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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>The following statement uses the <code>AVG()<\/code> function to calculate the average of all values in the <code>t<\/code> table:<\/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> <span class=\"hljs-keyword\">AVG<\/span>(<span class=\"hljs-keyword\">ALL<\/span> val) <span class=\"hljs-keyword\">avg<\/span> \n<span class=\"hljs-keyword\">FROM<\/span> 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>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">avg<\/span>\n<span class=\"hljs-selector-tag\">--------<\/span>\n3<span class=\"hljs-selector-class\">.750000<\/span>\n(1 <span class=\"hljs-selector-tag\">row<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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>In this example, we use the <code>ALL<\/code> modifier, therefore, the average function considers all eight values in the <code>val<\/code> column in the calculation:<\/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\">(1 + 2 + 3 + 4 + 4 + 5 + 5 + 6) \/  8 = 3.75<\/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 statement uses the <code>AVG()<\/code> function with <code>DISTINCT<\/code> modifier:<\/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\">SELECT<\/span> <span class=\"hljs-keyword\">AVG<\/span>(<span class=\"hljs-keyword\">DISTINCT<\/span> val) <span class=\"hljs-keyword\">avg<\/span>\n<span class=\"hljs-keyword\">FROM<\/span> t;<\/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 result:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">avg<\/span>\n<span class=\"hljs-selector-tag\">--------<\/span>\n3<span class=\"hljs-selector-class\">.500000<\/span>\n(1 <span class=\"hljs-selector-tag\">row<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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>Because of the <code>DISTINCT<\/code> modifier, the <code>AVG()<\/code> function performs the calculation on distinct values:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">(1 + 2 + 3 + 4 + 5 + 6) \/ 6 = 3.5<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-avg-function-examples'>SQL Server AVG() function examples <a href=\"#sql-server-avg-function-examples\" class=\"anchor\" id=\"sql-server-avg-function-examples\" title=\"Anchor for SQL Server AVG() function examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s take some examples to see how the <code>AVG()<\/code> function works.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='1-basic-sql-server-avg-function-example'>1) Basic SQL Server AVG() function example <a href=\"#1-basic-sql-server-avg-function-example\" class=\"anchor\" id=\"1-basic-sql-server-avg-function-example\" title=\"Anchor for 1) Basic SQL Server AVG() function example\">#<\/a><\/h3>\n\n\n\n<p>The following example returns the average list price of all products:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" 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    <span class=\"hljs-keyword\">AVG<\/span>(list_price) <span class=\"hljs-keyword\">avg<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n    production.products;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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, the <code>AVG()<\/code> function returns a single value for the whole table.<\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">avg<\/span>\n<span class=\"hljs-selector-tag\">-----------<\/span>\n1520<span class=\"hljs-selector-class\">.591401<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><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>To make the average price easier to read, you can round it using the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-math-functions\/sql-server-round\/\">ROUND()<\/a> function and cast the result to a number with two decimal places:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" 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    <span class=\"hljs-keyword\">CAST<\/span>(<span class=\"hljs-keyword\">ROUND<\/span>(<span class=\"hljs-keyword\">AVG<\/span>(list_price),<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-built_in\">DEC<\/span>(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>)) <span class=\"hljs-keyword\">avg<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n    production.products;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><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>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">avg<\/span>\r\n<span class=\"hljs-selector-tag\">-------<\/span>\r\n1520<span class=\"hljs-selector-class\">.59<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><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<h3 class=\"wp-block-heading\" id='2-using-sql-server-avg-with-group-by-example'>2) Using SQL Server AVG() with GROUP BY example <a href=\"#2-using-sql-server-avg-with-group-by-example\" class=\"anchor\" id=\"2-using-sql-server-avg-with-group-by-example\" title=\"Anchor for 2) Using SQL Server AVG() with GROUP BY example\">#<\/a><\/h3>\n\n\n\n<p>If you use the <code>AVG()<\/code> function with a <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-group-by\/\">GROUP BY<\/a><\/code> clause, the <code>AVG()<\/code> function returns a single value for each group instead of a single value for the whole table.<\/p>\n\n\n\n<p>The following example uses the <code>AVG()<\/code> function with the <code>GROUP BY<\/code> clause to retrieve the average list price for each product category:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" 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    category_name,\n    <span class=\"hljs-keyword\">CAST<\/span>(<span class=\"hljs-keyword\">ROUND<\/span>(<span class=\"hljs-keyword\">AVG<\/span>(list_price),<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-built_in\">DEC<\/span>(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>))  avg_product_price\n<span class=\"hljs-keyword\">FROM<\/span>\n    production.products p\n    <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> production.categories c \n        <span class=\"hljs-keyword\">ON<\/span> c.category_id = p.category_id\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    category_name\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    category_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><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>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">category_name       | avg_product_price\n--------------------+------------------\nChildren Bicycles   | 287.79\nComfort Bicycles    | 682.12\nCruisers Bicycles   | 730.41\nCyclocross Bicycles | 2542.79\nElectric Bikes      | 3281.66\nMountain Bikes      | 1649.76\nRoad Bikes          | 3175.36\n(7 rows)<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='3-using-sql-server-avg-in-having-clause-example'>3) Using SQL Server AVG() in HAVING clause example <a href=\"#3-using-sql-server-avg-in-having-clause-example\" class=\"anchor\" id=\"3-using-sql-server-avg-in-having-clause-example\" title=\"Anchor for 3) Using SQL Server AVG() in HAVING clause example\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the <code>AVG()<\/code> function in the <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-having\/\">HAVING<\/a><\/code> clause to retrieve only brands whose average list prices are more than 500:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" 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    brand_name,\n    <span class=\"hljs-keyword\">CAST<\/span>(<span class=\"hljs-keyword\">ROUND<\/span>(<span class=\"hljs-keyword\">AVG<\/span>(list_price),<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-built_in\">DEC<\/span>(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>)) avg_product_price\n<span class=\"hljs-keyword\">FROM<\/span>\n    production.products p\n    <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> production.brands c <span class=\"hljs-keyword\">ON<\/span> c.brand_id = p.brand_id\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    brand_name\n<span class=\"hljs-keyword\">HAVING<\/span>\n    <span class=\"hljs-keyword\">AVG<\/span>(list_price) &gt; <span class=\"hljs-number\">500<\/span>\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n    avg_product_price;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><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>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">brand_name   | avg_product_price\n-------------+-------------------\nSun Bicycles | 524.47\nHaro         | 621.99\nRitchey      | 749.99\nElectra      | 761.01\nSurly        | 1331.75\nHeller       | 2173.00\nTrek         | 2500.06\n(7 rows)<\/code><\/span><\/pre>\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-group-by\/\">GROUP BY<\/a><\/code> clause divides the products by brands into groups.<\/li>\n\n\n\n<li>Second, the <code>AVG()<\/code> function calculates the average list price for each group.<\/li>\n\n\n\n<li>Third, the <code><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-having\/\">HAVING<\/a><\/code> clause removes the brand whose average list price is less than 500.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>AVG()<\/code> function to calculate the average value from a group of values.<\/li>\n\n\n\n<li>Use the <code>AVG()<\/code> function with the <code>GROUP BY<\/code> clause to calculate the average of each group.<\/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=\"1020\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/\"\n\t\t\t\tdata-post-title=\"SQL Server AVG() 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=\"1020\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/\"\n\t\t\t\tdata-post-title=\"SQL Server AVG() 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 Server AVG() function to calculate the average value from a group of values.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1006,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1020","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 AVG() Function<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL Server AVG() function to calculate the average value from a group of values.\" \/>\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-aggregate-functions\/sql-server-avg\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server AVG() Function\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL Server AVG() function to calculate the average value from a group of values.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-04T00:44:51+00:00\" \/>\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=\"2 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-aggregate-functions\\\/sql-server-avg\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-aggregate-functions\\\/sql-server-avg\\\/\",\"name\":\"SQL Server AVG() Function\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"datePublished\":\"2018-10-21T10:49:09+00:00\",\"dateModified\":\"2024-04-04T00:44:51+00:00\",\"description\":\"This tutorial shows you how to use the SQL Server AVG() function to calculate the average value from a group of values.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-aggregate-functions\\\/sql-server-avg\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-aggregate-functions\\\/sql-server-avg\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-aggregate-functions\\\/sql-server-avg\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Aggregate Functions\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-aggregate-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server AVG() 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 AVG() Function","description":"This tutorial shows you how to use the SQL Server AVG() function to calculate the average value from a group of values.","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-aggregate-functions\/sql-server-avg\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server AVG() Function","og_description":"This tutorial shows you how to use the SQL Server AVG() function to calculate the average value from a group of values.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2024-04-04T00:44:51+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/","name":"SQL Server AVG() Function","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"datePublished":"2018-10-21T10:49:09+00:00","dateModified":"2024-04-04T00:44:51+00:00","description":"This tutorial shows you how to use the SQL Server AVG() function to calculate the average value from a group of values.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/sql-server-avg\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Aggregate Functions","item":"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/"},{"@type":"ListItem","position":3,"name":"SQL Server AVG() 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\/1020","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=1020"}],"version-history":[{"count":4,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1020\/revisions"}],"predecessor-version":[{"id":3705,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1020\/revisions\/3705"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/1006"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=1020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}