<?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>minimum Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/minimum/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/minimum/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Mon, 05 Apr 2021 13:03:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>SQL Queries</title>
		<link>https://www.scmgalaxy.com/tutorials/sql-queries/</link>
					<comments>https://www.scmgalaxy.com/tutorials/sql-queries/#respond</comments>
		
		<dc:creator><![CDATA[Joydeep M]]></dc:creator>
		<pubDate>Mon, 05 Apr 2021 13:03:02 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[alias]]></category>
		<category><![CDATA[Case]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[having]]></category>
		<category><![CDATA[maximum]]></category>
		<category><![CDATA[minimum]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[Update]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/?p=5796</guid>

					<description><![CDATA[<p> 👉  To give a table, or a column in a table, a temporary name we can use Alias: For example [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/sql-queries/">SQL Queries</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><strong> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" />  To give a table, or a column in a table, a temporary name we can use Alias:</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT "column_name" AS "column_Alias" FROM "table_name";</strong></code></pre>



<p class="wp-block-paragraph">For example we have a table with column_name as &#8220;<strong>SNo&#8221; </strong>, &#8220;<strong>Country</strong>&#8221; and &#8220;<strong>Capital</strong>&#8221; and we want to update it as &#8220;<strong>Serial Number</strong>&#8221; , &#8220;<strong>State</strong>&#8221; and &#8220;<strong>Country_Capital </strong>then we will run the following command:</p>



<script src="https://gist.github.com/Joydeep-cotocus/f6ede3b49a0364ccf16604490c48a399.js"></script>



<p class="wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> To count the number of rows in the table:</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT COUNT(column_name) AS (alias_name) FROM table_name;</strong></code></pre>



<p class="wp-block-paragraph">For example we want to count number of orders placed by a particular customer from customer_table:</p>



<script src="https://gist.github.com/Joydeep-cotocus/0436d5c8365a64c8e58995edd2419abd.js"></script>



<p class="wp-block-paragraph">This will show the count of numbers of order places by the customer id &#8220;CG-1234&#8242; and the products ordered.</p>



<p class="wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> To add the values in a columns we use Sum command:</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT SUM (column_name) FROM table_name;</strong></code></pre>



<p class="wp-block-paragraph">For example we want to add the profit amount from the sales table:</p>



<script src="https://gist.github.com/Joydeep-cotocus/e9e4a806d7e4275e8f2041fea7b98285.js"></script>



<p class="wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> To find out an average for a column in the table:</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT AVG (column_name) FROM table_name;</strong></code></pre>



<p class="wp-block-paragraph">For example we need to find the average age of the customers from customer table:</p>



<script src="https://gist.github.com/Joydeep-cotocus/0fcdd7adfda8ba89bca71e3066372c93.js"></script>



<p class="wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" />To find the minimum and the maximum value in a table:</strong></p>



<ul class="wp-block-list"><li>Minimum</li></ul>



<pre class="wp-block-code"><code><strong>SELECT MIN (column_name) FROM table_name;</strong></code></pre>



<p class="wp-block-paragraph">For example we want to find the minimum order sale made for a product from sales table:</p>



<script src="https://gist.github.com/Joydeep-cotocus/b6e7bf0b41b16fab3cd213d4eab8f634.js"></script>



<ul class="wp-block-list"><li>Maximum</li></ul>



<pre class="wp-block-code"><code><strong>SELECT MAX (column_name) FROM table_name;</strong></code></pre>



<p class="wp-block-paragraph">For example we want to find the maximum order sale made for a product from sales table:</p>



<script src="https://gist.github.com/Joydeep-cotocus/1015c106530bf6c170620e7d74c34284.js"></script>



<p class="has-text-align-left wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> To groups rows that have the same values into summary rows, like &#8220;find the number of customers in each region&#8221; we use GROUP BY statement. The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT "column_name","function-type" (column_name) FROM table_name Group By "column-name";</strong></code></pre>



<p class="wp-block-paragraph">For example we need to find the number orders places in each region in the table:</p>



<script src="https://gist.github.com/Joydeep-cotocus/4410047ac5955b5e7d7992b07508ca15.js"></script>



<p class="wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong> <strong>To make conditions for aggregate functions we use HAVING clause. The difference between Having clause and Where clause is that we cannot make conditions in aggregate functions whereas we can make conditions in aggregate functions using Having clause.</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT column_name, AGGREGATE FUNCTION column_name FROM tables GROUP BY (column1) HAVING condition;</strong></code></pre>



<p class="wp-block-paragraph">For example we have some set of customers in four regions and we want to see in which region the count of customers is more than 200. In this scenario we will use the HAVING clause and set a condition of count more than 200.</p>



<script src="https://gist.github.com/Joydeep-cotocus/a6e3f81522f57ff8686cdcb7c6534dbb.js"></script>



<p class="wp-block-paragraph">This command will show the count of customers in the regions where it is more than 200.</p>



<p class="wp-block-paragraph"><strong><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong> <strong>To go through a condition and return a value when the first condition is met (like an if-then-else statement) &#8220;CASE&#8221; statement is used. So, once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the <code>ELSE</code> clause.</strong></p>



<pre class="wp-block-code"><code>Syntax: <strong>SELECT * CASE WHEN condition THEN result ELSE result END;</strong></code></pre>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/sql-queries/">SQL Queries</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/sql-queries/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
