<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Salary Archives - The Code Developer</title>
	<atom:link href="https://www.thecodedeveloper.com/tag/salary/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.thecodedeveloper.com/tag/salary/</link>
	<description>The Code Developer is a Programming Blog.</description>
	<lastBuildDate>Fri, 25 Jan 2019 12:50:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>MySQL query to find the highest salary from each department</title>
		<link>https://www.thecodedeveloper.com/find-highest-salary/</link>
					<comments>https://www.thecodedeveloper.com/find-highest-salary/#comments</comments>
		
		<dc:creator><![CDATA[Vikas Kumar]]></dc:creator>
		<pubDate>Tue, 17 Jul 2018 12:59:59 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Salary]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=2940</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1000" height="663" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="highest salary" decoding="async" fetchpriority="high" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary.png 1000w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary-442x293.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary-768x509.png 768w" sizes="(max-width: 1000px) 100vw, 1000px" /></div>
<p>In article we will explain how to write a MySQL query to find the highest salary from each department from the employees table. Read Also : Find The Nth Highest Employee Salary From An Employee Table In MySql Find the highest salary from each department Let&#8217;s create a simple example of employees table. We will [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/find-highest-salary/">MySQL query to find the highest salary from each department</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1000" height="663" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="highest salary" decoding="async" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary.png 1000w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary-442x293.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/find-highest-salary-768x509.png 768w" sizes="(max-width: 1000px) 100vw, 1000px" /></div><p>In article we will explain how to write a MySQL query to find the <strong>highest salary</strong> from each department from the employees table.</p>
<p>Read Also : <a href="https://www.thecodedeveloper.com/nth-highest-employee-salary/" rel="noopener" target="_blank">Find The Nth Highest Employee Salary From An Employee Table In MySql</a></p>
<h2>Find the highest salary from each department</h2>
<p>Let&#8217;s create a simple example of employees table. We will populate this table with id, name, salary and department of employees.</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM employees;
</pre>
<div id="tablepress-30-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-30" class="tablepress tablepress-id-30 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">id</th><th class="column-2">name</th><th class="column-3">salary</th><th class="column-4">department</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">1</td><td class="column-2">Tom</td><td class="column-3">4000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-3">
	<td class="column-1">2</td><td class="column-2">Sam</td><td class="column-3">6000</td><td class="column-4">Sales</td>
</tr>
<tr class="row-4">
	<td class="column-1">3</td><td class="column-2">Bob</td><td class="column-3">3000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-5">
	<td class="column-1">4</td><td class="column-2">Alen</td><td class="column-3">8000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-6">
	<td class="column-1">5</td><td class="column-2">Jack</td><td class="column-3">12000</td><td class="column-4">Marketing</td>
</tr>
<tr class="row-7">
	<td class="column-1">6</td><td class="column-2">Charlie</td><td class="column-3">8000</td><td class="column-4">Human Resources</td>
</tr>
<tr class="row-8">
	<td class="column-1">7</td><td class="column-2">Harry</td><td class="column-3">6000</td><td class="column-4">Marketing</td>
</tr>
<tr class="row-9">
	<td class="column-1">8</td><td class="column-2">Jacob</td><td class="column-3">4000</td><td class="column-4">Human Resources</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-30 from cache -->
<p>The following MySQL statement find the maximum salary from each department, you will be required to use the <a href="https://www.thecodedeveloper.com/mysql-group/" rel="noopener" target="_blank">GROUP BY</a> clause with the SELECT query.</p>
<pre class="brush: php; title: ; notranslate">
SELECT department, MAX(salary)  
FROM employees 
GROUP BY department
ORDER BY MAX(salary) DESC;
</pre>
<div id="tablepress-36-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-36" class="tablepress tablepress-id-36 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">department</th><th class="column-2">MAX(salary)</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">Marketing</td><td class="column-2">12000</td>
</tr>
<tr class="row-3">
	<td class="column-1">Human Resources</td><td class="column-2">8000</td>
</tr>
<tr class="row-4">
	<td class="column-1">Technology</td><td class="column-2">8000</td>
</tr>
<tr class="row-5">
	<td class="column-1">Sales</td><td class="column-2">6000</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-36 from cache -->
<p>The post <a href="https://www.thecodedeveloper.com/find-highest-salary/">MySQL query to find the highest salary from each department</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/find-highest-salary/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Retrieve highest and lowest salary From An Employee Table In MySql</title>
		<link>https://www.thecodedeveloper.com/retrieve-highest-and-lowest-salary/</link>
					<comments>https://www.thecodedeveloper.com/retrieve-highest-and-lowest-salary/#respond</comments>
		
		<dc:creator><![CDATA[Vikas Kumar]]></dc:creator>
		<pubDate>Mon, 16 Jul 2018 13:02:21 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Salary]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=2912</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1000" height="663" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Retrieve highest and lowest salary" decoding="async" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary.png 1000w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary-442x293.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary-768x509.png 768w" sizes="(max-width: 1000px) 100vw, 1000px" /></div>
<p>In article we will explain how to write a MySQL query to Retrieve highest and lowest salary from the employees table. Read Also : MySQL Query To Find The Second Highest Salary Retrieve highest and lowest salary From An employees Table First let&#8217;s create a simple example of employees table. We will populate this table [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/retrieve-highest-and-lowest-salary/">Retrieve highest and lowest salary From An Employee Table In MySql</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1000" height="663" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Retrieve highest and lowest salary" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary.png 1000w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary-442x293.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/07/retrieve-highest-lowest-salary-768x509.png 768w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></div><p>In article we will explain how to write a MySQL query to <strong>Retrieve highest and lowest salary</strong> from the employees table.</p>
<p>Read Also : <a href="https://www.thecodedeveloper.com/second-highest-salary-mysql/" rel="noopener">MySQL Query To Find The Second Highest Salary</a></p>
<h2>Retrieve highest and lowest salary From An employees Table</h2>
<p>First let&#8217;s create a simple example of employees table. We will populate this table with id, name, salary and department of employees.</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM employees;
</pre>
<div id="tablepress-30-no-2-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-30-no-2" class="tablepress tablepress-id-30 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">id</th><th class="column-2">name</th><th class="column-3">salary</th><th class="column-4">department</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">1</td><td class="column-2">Tom</td><td class="column-3">4000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-3">
	<td class="column-1">2</td><td class="column-2">Sam</td><td class="column-3">6000</td><td class="column-4">Sales</td>
</tr>
<tr class="row-4">
	<td class="column-1">3</td><td class="column-2">Bob</td><td class="column-3">3000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-5">
	<td class="column-1">4</td><td class="column-2">Alen</td><td class="column-3">8000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-6">
	<td class="column-1">5</td><td class="column-2">Jack</td><td class="column-3">12000</td><td class="column-4">Marketing</td>
</tr>
<tr class="row-7">
	<td class="column-1">6</td><td class="column-2">Charlie</td><td class="column-3">8000</td><td class="column-4">Human Resources</td>
</tr>
<tr class="row-8">
	<td class="column-1">7</td><td class="column-2">Harry</td><td class="column-3">6000</td><td class="column-4">Marketing</td>
</tr>
<tr class="row-9">
	<td class="column-1">8</td><td class="column-2">Jacob</td><td class="column-3">4000</td><td class="column-4">Human Resources</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-30-no-2 from cache -->
<p>The following MySQL statement finds the highest and lowest salary From An employees Table:</p>
<pre class="brush: php; title: ; notranslate">
SELECT MAX(salary), MIN(salary)
FROM employees;
</pre>
<div id="tablepress-35-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-35" class="tablepress tablepress-id-35 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">MAX(salary)</th><th class="column-2">MIN(salary)</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">12000</td><td class="column-2">3000</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-35 from cache -->
<p>In above MySQl query we used-<br />
The <a href="https://www.thecodedeveloper.com/mysql-max-function/">MySQL MAX</a> function returns the maximum value in a set of values.<br />
The <a href="https://www.thecodedeveloper.com/mysql-min-function/">MySQL MIN</a> function returns the minimum value in a set of values.</p>
<p>The post <a href="https://www.thecodedeveloper.com/retrieve-highest-and-lowest-salary/">Retrieve highest and lowest salary From An Employee Table In MySql</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/retrieve-highest-and-lowest-salary/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Find the Nth highest employee salary from an Employee table in MySql</title>
		<link>https://www.thecodedeveloper.com/nth-highest-employee-salary/</link>
					<comments>https://www.thecodedeveloper.com/nth-highest-employee-salary/#respond</comments>
		
		<dc:creator><![CDATA[Vikas Kumar]]></dc:creator>
		<pubDate>Mon, 11 Jun 2018 17:41:15 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Salary]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=2472</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="1280" height="853" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Find the Nth highest employee salary from an Employee table" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary.jpg 1280w, https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary-442x295.jpg 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary-768x512.jpg 768w, https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary-1024x682.jpg 1024w" sizes="auto, (max-width: 1280px) 100vw, 1280px" /></div>
<p>Find the Nth highest employee salary from an Employee table is the most common question asked in interviews. There are many ways to get Nth highest employee salary based upon which database you are using. In this article i am using MySQL database for demonstration. Read Also : MySQL Query To Find The Second Highest [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/nth-highest-employee-salary/">Find the Nth highest employee salary from an Employee table in MySql</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="1280" height="853" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Find the Nth highest employee salary from an Employee table" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary.jpg 1280w, https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary-442x295.jpg 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary-768x512.jpg 768w, https://www.thecodedeveloper.com/wp-content/uploads/2018/06/nth-highest-employee-salary-1024x682.jpg 1024w" sizes="auto, (max-width: 1280px) 100vw, 1280px" /></div><p>Find the <strong>Nth highest employee salary</strong> from an Employee table is the most common question asked in interviews. There are many ways to get Nth highest employee salary based upon which database you are using. In this article i am using MySQL database for demonstration.</p>
<p>Read Also : <a href="https://www.thecodedeveloper.com/second-highest-salary-mysql/" rel="noopener">MySQL Query To Find The Second Highest Salary</a></p>
<h2>Find the Nth highest employee salary</h2>
<p>Let&#8217;s create a simple example of employees table. We will populate this table with id, name, salary and department of employees.</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM employees;
</pre>
<div id="tablepress-30-no-3-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-30-no-3" class="tablepress tablepress-id-30 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">id</th><th class="column-2">name</th><th class="column-3">salary</th><th class="column-4">department</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">1</td><td class="column-2">Tom</td><td class="column-3">4000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-3">
	<td class="column-1">2</td><td class="column-2">Sam</td><td class="column-3">6000</td><td class="column-4">Sales</td>
</tr>
<tr class="row-4">
	<td class="column-1">3</td><td class="column-2">Bob</td><td class="column-3">3000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-5">
	<td class="column-1">4</td><td class="column-2">Alen</td><td class="column-3">8000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-6">
	<td class="column-1">5</td><td class="column-2">Jack</td><td class="column-3">12000</td><td class="column-4">Marketing</td>
</tr>
<tr class="row-7">
	<td class="column-1">6</td><td class="column-2">Charlie</td><td class="column-3">8000</td><td class="column-4">Human Resources</td>
</tr>
<tr class="row-8">
	<td class="column-1">7</td><td class="column-2">Harry</td><td class="column-3">6000</td><td class="column-4">Marketing</td>
</tr>
<tr class="row-9">
	<td class="column-1">8</td><td class="column-2">Jacob</td><td class="column-3">4000</td><td class="column-4">Human Resources</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-30-no-3 from cache -->
<h3>Method 1 – Nth highest salary in MySQL using LIMIT clause:</h3>
<pre class="brush: php; title: ; notranslate">
SELECT DISTINCT(salary) FROM employees ORDER BY salary DESC LIMIT N-1, 1;
</pre>
<h4>2nd highest salary in MySQL using LIMIT clause:</h4>
<pre class="brush: php; title: ; notranslate">
SELECT DISTINCT(salary) FROM employees ORDER BY salary DESC LIMIT 1,1;
</pre>
<div id="tablepress-31-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-31" class="tablepress tablepress-id-31 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">salary</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">8000</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-31 from cache -->
<h4>3rd highest salary in MySQL using LIMIT clause:</h4>
<pre class="brush: php; title: ; notranslate">
SELECT DISTINCT(salary) FROM employees ORDER BY salary DESC LIMIT 2,1;
</pre>
<div id="tablepress-32-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-32" class="tablepress tablepress-id-32 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">salary</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">6000</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-32 from cache -->
<h3>Method 2 – Nth highest salary in MySQL using SubQuery:</h3>
<pre class="brush: php; title: ; notranslate">
SELECT DISTINCT( salary ) 
FROM   employees Emp1 
WHERE  N = (SELECT Count(DISTINCT ( Emp2.salary )) 
                FROM   employees Emp2 
                WHERE  Emp2.salary &gt;= Emp1.salary); 
</pre>
<p>Here, replace the N with any number. For example, if you want to find 5th highest salary , then replace N with 5 like below query –</p>
<pre class="brush: php; title: ; notranslate">
SELECT DISTINCT( salary ) 
FROM   employees Emp1 
WHERE  5 = (SELECT Count(DISTINCT ( Emp2.salary )) 
            FROM   employees Emp2 
            WHERE  Emp2.salary &gt;= Emp1.salary);
</pre>
<div id="tablepress-33-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-33" class="tablepress tablepress-id-33 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">salary</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">3000</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-33 from cache -->
<p>Now suppose based on the above table you want to get all employees have Nth highest salary with all details. For example, if you want to find all employees have 3rd highest salary with all details:</p>
<pre class="brush: php; title: ; notranslate">
SELECT * 
FROM   employees Emp1 
WHERE  3 = (SELECT Count(DISTINCT ( Emp2.salary )) 
            FROM   employees Emp2 
            WHERE  Emp2.salary &gt;= Emp1.salary);
</pre>
<div id="tablepress-34-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-34" class="tablepress tablepress-id-34 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">id</th><th class="column-2">name</th><th class="column-3">salary</th><th class="column-4">department</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">2</td><td class="column-2">Sam</td><td class="column-3">6000</td><td class="column-4">Sales</td>
</tr>
<tr class="row-3">
	<td class="column-1">7</td><td class="column-2">Harry</td><td class="column-3">6000</td><td class="column-4">Marketing</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-34 from cache -->
<p>The post <a href="https://www.thecodedeveloper.com/nth-highest-employee-salary/">Find the Nth highest employee salary from an Employee table in MySql</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/nth-highest-employee-salary/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL AVG Function</title>
		<link>https://www.thecodedeveloper.com/mysql-avg-function/</link>
					<comments>https://www.thecodedeveloper.com/mysql-avg-function/#respond</comments>
		
		<dc:creator><![CDATA[Aastha Tyagi]]></dc:creator>
		<pubDate>Sun, 21 Jan 2018 09:18:24 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySql Function]]></category>
		<category><![CDATA[Salary]]></category>
		<guid isPermaLink="false">https://www.thecodedeveloper.com/?p=2514</guid>

					<description><![CDATA[<div style="margin-bottom:20px;"><img width="939" height="469" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="MySQL AVG" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function.png 939w, https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function-442x221.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function-768x384.png 768w" sizes="auto, (max-width: 939px) 100vw, 939px" /></div>
<p>Introduction to MySQL AVG Function This MySQL tutorial explains how to use the MySQL AVG Function with syntax and examples. The AVG() function returns the average value of a numeric column. AVG() Syntax SELECT AVG(column_name) FROM table_name WHERE condition; To understand MySQL AVG Function, consider an &#8220;books&#8221; table, which is having the following records: SELECT [&#8230;]</p>
<p>The post <a href="https://www.thecodedeveloper.com/mysql-avg-function/">MySQL AVG Function</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div style="margin-bottom:20px;"><img width="939" height="469" src="https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="MySQL AVG" decoding="async" loading="lazy" srcset="https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function.png 939w, https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function-442x221.png 442w, https://www.thecodedeveloper.com/wp-content/uploads/2018/01/MySQL-AVG-Function-768x384.png 768w" sizes="auto, (max-width: 939px) 100vw, 939px" /></div><h2>Introduction to MySQL AVG Function</h2>
<p>This MySQL tutorial explains how to use the <strong>MySQL AVG</strong> Function with syntax and examples. The AVG() function returns the average value of a numeric column.</p>
<h3>AVG() Syntax</h3>
<pre class="brush: php; title: ; notranslate">
SELECT AVG(column_name)
FROM table_name
WHERE condition;
</pre>
<p>To understand <strong>MySQL AVG</strong> Function, consider an &#8220;books&#8221; table, which is having the following records:</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM books;
</pre>
<div id="tablepress-14-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-14" class="tablepress tablepress-id-14 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">BookId</th><th class="column-2">BookName</th><th class="column-3">Price</th><th class="column-4">Author</th><th class="column-5">publishedDate</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">1</td><td class="column-2">Learning PHP, MySQL, and JavaScript</td><td class="column-3">17</td><td class="column-4">Robin Nixon</td><td class="column-5">2017-02-02</td>
</tr>
<tr class="row-3">
	<td class="column-1">2</td><td class="column-2">Ubuntu: Up and Running</td><td class="column-3">23</td><td class="column-4">Robin Nixon</td><td class="column-5">2017-03-23</td>
</tr>
<tr class="row-4">
	<td class="column-1">3</td><td class="column-2">PHP and MySQL Web Development</td><td class="column-3">12</td><td class="column-4">Luke Welling</td><td class="column-5">2017-06-14</td>
</tr>
<tr class="row-5">
	<td class="column-1">4</td><td class="column-2">Murach's PHP and MySQL</td><td class="column-3">14</td><td class="column-4">Joel Murach</td><td class="column-5">2017-06-17</td>
</tr>
<tr class="row-6">
	<td class="column-1">5</td><td class="column-2">Murach's Java Programming</td><td class="column-3">62</td><td class="column-4">Joel Murach</td><td class="column-5">2017-07-28</td>
</tr>
<tr class="row-7">
	<td class="column-1">6</td><td class="column-2">Head first php mysql</td><td class="column-3">22</td><td class="column-4">Lynn Beighley</td><td class="column-5">2017-07-31</td>
</tr>
<tr class="row-8">
	<td class="column-1">7</td><td class="column-2">Head first sql</td><td class="column-3">11</td><td class="column-4">Lynn Beighley</td><td class="column-5">2017-09-10</td>
</tr>
<tr class="row-9">
	<td class="column-1">8</td><td class="column-2">HTML5 for IOS and Android: A Beginner's Guide</td><td class="column-3">4</td><td class="column-4">Robin Nixon</td><td class="column-5">2017-09-12</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-14 from cache -->
<h3>AVG Function Example</h3>
<h4>Examples 1:</h4>
<p>The following SQL statement finds the average price of all books:</p>
<pre class="brush: php; title: ; notranslate">
SELECT AVG(Price) AS  &quot;Avg Price&quot;
FROM books;
</pre>
<div id="tablepress-25-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-25" class="tablepress tablepress-id-25 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">Avg Price</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">20.6250</td>
</tr>
</tbody>
</table>

</div>
<p>Below is a selection from the &#8220;employees&#8221; table, which is having the following records:</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM employees;
</pre>
<div id="tablepress-1-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-1" class="tablepress tablepress-id-1 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">id</th><th class="column-2">name</th><th class="column-3">salary</th><th class="column-4">department</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">1</td><td class="column-2">Tom</td><td class="column-3">4000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-3">
	<td class="column-1">2</td><td class="column-2">Sam</td><td class="column-3">6000</td><td class="column-4">Sales</td>
</tr>
<tr class="row-4">
	<td class="column-1">3</td><td class="column-2">Bob</td><td class="column-3">3000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-5">
	<td class="column-1">4</td><td class="column-2">Alen</td><td class="column-3">8000</td><td class="column-4">Technology</td>
</tr>
<tr class="row-6">
	<td class="column-1">5</td><td class="column-2">Jack</td><td class="column-3">12000</td><td class="column-4">Marketing</td>
</tr>
</tbody>
</table>

</div><!-- #tablepress-1 from cache -->
<h3>Example 2: With Single Expression</h3>
<p>Now suppose based on the above table you want to know how the average salary of all employees whose salary is above 6000.</p>
<pre class="brush: php; title: ; notranslate">
SELECT AVG(salary) AS &quot;Avg Salary&quot;
FROM employees
WHERE salary &gt; 6000;
</pre>
<div id="tablepress-26-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-26" class="tablepress tablepress-id-26 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">Avg Salary</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">10000.0000</td>
</tr>
</tbody>
</table>

</div>
<h3>Example 3: Using GROUP BY</h3>
<p>In some cases, you will be required to use the <a href="https://www.thecodedeveloper.com/mysql-group/">GROUP BY</a> clause with the AVG function.</p>
<p>For example, you could also use the AVG function to calculate average salary for each department:</p>
<pre class="brush: php; title: ; notranslate">
SELECT department, AVG(salary) AS &quot;Avg salary&quot;
FROM employees
GROUP BY department;
</pre>
<div id="tablepress-27-scroll-wrapper" class="tablepress-scroll-wrapper">

<table id="tablepress-27" class="tablepress tablepress-id-27 tablepress-responsive">
<thead>
<tr class="row-1">
	<th class="column-1">department</th><th class="column-2">Avg salary</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">Marketing</td><td class="column-2">12000.0000</td>
</tr>
<tr class="row-3">
	<td class="column-1">Sales</td><td class="column-2">6000.0000</td>
</tr>
<tr class="row-4">
	<td class="column-1">Technology</td><td class="column-2">5000.0000</td>
</tr>
</tbody>
</table>

</div>
<p>The post <a href="https://www.thecodedeveloper.com/mysql-avg-function/">MySQL AVG Function</a> appeared first on <a href="https://www.thecodedeveloper.com">The Code Developer</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.thecodedeveloper.com/mysql-avg-function/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
