<?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>Aggregate Function &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/aggregate-function/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 09 Oct 2018 19:45:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: How to Aggregate data and perform Multiplication?</title>
		<link>https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/</link>
					<comments>https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 15 Oct 2018 16:16:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Aggregate Function]]></category>
		<category><![CDATA[Aggregate Multiplication]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[EXP]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7438</guid>

					<description><![CDATA[In this post, I am sharing an aggregate query for calculating Multiplication for each group in SQL Server. We are using an aggregate function like MAX(), SUM(). But there is no any aggregate function for Multiplication. We can use EXP/LOG expression for this exercise. EXP returns the exponential value and LOG returns the natural logarithm [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&#038;title=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" data-a2a-url="https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/" data-a2a-title="SQL Server: How to Aggregate data and perform Multiplication?"></a></p><p>In this post, I am sharing an aggregate query for calculating Multiplication for each group in SQL Server. We are using an aggregate function like MAX(), SUM(). But there is no any aggregate function for Multiplication. </p>
<p>We can use EXP/LOG expression for this exercise. EXP returns the exponential value and LOG returns the natural logarithm of the specified float expression.</p>
<p><strong>Please check the below demonstration: </strong></p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_GroupNumber (GroupName VARCHAR(10), GroupValue INT)

INSERT INTO tbl_GroupNumber VALUES
('A',10),('B',15),('C',20),('D',30)
,('B',30),('C',60),('D',40),('D',50)
,('A',70),('B',40),('C',10),('B',90)
GO</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	GroupName 
	,EXP(SUM(LOG(GroupValue))) AS GroupValue
FROM tbl_GroupNumber
GROUP BY GroupName</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">GroupName  GroupValue
---------- ----------------------
A          700
B          1620000
C          12000
D          60000</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL 9.4: Using FILTER CLAUSE, multiple COUNT(*) in one SELECT Query for Different Groups</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/</link>
					<comments>https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 11 Aug 2016 19:54:33 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Aggregate Function]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[FILTER CLAUSE]]></category>
		<category><![CDATA[FILTER GROUP BY]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL 9.4]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3495</guid>

					<description><![CDATA[PostgreSQL 9.4 has introduced one of the very good FILTER CLAUSE which is used to apply filters in aggregate functions. Using FILTER, You can use different types of aggregate functions without applying any GROUP BY CLAUSE. Now Imagine, that I have one Student table and I want total number of Students based different grades. What [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&#038;title=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/" data-a2a-title="PostgreSQL 9.4: Using FILTER CLAUSE, multiple COUNT(*) in one SELECT Query for Different Groups"></a></p><p>PostgreSQL 9.4 has introduced one of the very good FILTER CLAUSE which is used to apply filters in aggregate functions. </p>
<p><strong>Using FILTER, You can use different types of aggregate functions without applying any GROUP BY CLAUSE.</strong> </p>
<blockquote><p>Now Imagine, that I have one Student table and I want total number of Students based different grades.<br />
What happened without FILTER CLAUSE, We have to perform this calculation in the individual SELECT query.</p></blockquote>
<blockquote><p>But with the use of FILTER CLAUSE we can perform aggregation based on different FILTER values in a single SQL Query. </p></blockquote>
<p><strong>Below is a small demonstration of this:</strong></p>
<p><strong>Create one Student table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT PRIMARY KEY
	,StudentName CHARACTER VARYING
	,Marks INTEGER
);

INSERT INTO tbl_Students 
VALUES (1,'Anvesh',88),(2,'Jenny',55),(3,'Tushar',85)
,(4,'Kavita',75),(5,'Manas',42),(6,'Martin',69)
,(7,'Roy',95),(8,'Benny',92),(9,'Neevan',82)
,(10,'Lee',43),(11,'Loother',65),(12,'Eric',58);</pre> </p>
<p><strong>Apply FILTER clause to count number of Students based on Marks:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	COUNT(1) AS TotalStudents 
	,COUNT(1) FILTER (WHERE Marks BETWEEN 40 AND 60) AS TotalGrade_C
	,COUNT(1) FILTER (WHERE Marks BETWEEN 60 AND 80) AS TotalGrade_B
	,COUNT(1) FILTER (WHERE Marks BETWEEN 80 AND 100) AS TotalGrade_A	
FROM tbl_Students;

/* Result:
-------------- --------------- --------------- ---------------
TotalStudents |  TotalGrade_C |  TotalGrade_B |  TotalGrade_A
--------------|---------------|---------------|---------------
      12      |       4       |       3       |       5
-------------- --------------- --------------- ---------------
 */</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
