<?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 &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/aggregate/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>Fri, 06 Oct 2017 18:52:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Puzzle: SQL Advance Query &#8211; Use STUFF() and form the aggregate of columns</title>
		<link>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/</link>
					<comments>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 20 Oct 2017 16:16:17 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[aggregate]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Advance Query]]></category>
		<category><![CDATA[SQL Interview]]></category>
		<category><![CDATA[SQL Problem]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[stuff]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5841</guid>

					<description><![CDATA[Check the below input data and expected output to merge the driven car&#8217;s data like which car has driven by which drivers and form the aggregate the result for the same car. Input Data: [crayon-6aabb79d64946798519131/] Expected Output: [crayon-6aabb79d6494b361486976/] Create a table with sample data: [crayon-6aabb79d6494c664347473/] Solution: [crayon-6aabb79d6494d963905327/] Please try the different solutions for this puzzle [&#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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&amp;linkname=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" 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%2F2017%2F10%2Fsql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns%2F&#038;title=SQL%20Puzzle%3A%20SQL%20Advance%20Query%20%E2%80%93%20Use%20STUFF%28%29%20and%20form%20the%20aggregate%20of%20columns" data-a2a-url="https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/" data-a2a-title="SQL Puzzle: SQL Advance Query – Use STUFF() and form the aggregate of columns"></a></p><p>Check the below input data and expected output to merge the driven car&#8217;s data like which car has driven by which drivers and form the aggregate the result for the same car.</p>
<p><strong>Input Data:</strong></p>
<pre class="crayon-plain-tag">CarName    Rout                 Driver     Year
---------- -------------------- ---------- -----------
Mobilio    hyd - ahd            Anvesh     2017
HCity      ahd - raj            Mukesh     2016
Mobilio    kadi - abu           Mukesh     2016
Duster     mha - dlh            Nupur      2017
Duster     hyd - ahd            Anvesh     2016
Duster     bha - ahd            Manish     2015</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">CarName    DrivenDetails
---------- ------------------------------------------------------------------------------------------------------
Duster     Rout:mha - dlh, driven by Nupur in Year  2017, Rout:hyd - ahd, driven by Anvesh in Year  2016, Rout:bha - ahd, driven by Manish in Year  2015
HCity      Rout:ahd - raj, driven by Mukesh in Year  2016
Mobilio    Rout:hyd - ahd, driven by Anvesh in Year  2017, Rout:kadi - abu, driven by Mukesh in Year  2016</pre> </p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE Cars 
(
	CarName VARCHAR(10)
	,Rout VARCHAR(20)
	,Driver VARCHAR(10)
	,Year INT
)
GO
 
INSERT INTO Cars VALUES
('Mobilio','hyd - ahd', 'Anvesh',2017)
,('HCity','ahd - raj', 'Mukesh',2016)
,('Mobilio','kadi - abu', 'Mukesh',2016)
,('Duster','mha - dlh', 'Nupur',2017)
,('Duster','hyd - ahd', 'Anvesh',2016)
,('Duster','bha - ahd', 'Manish',2015)
GO</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">SELECT b.CarName 
	,STUFF 
	((
	SELECT ', Rout:' + Rout + ', driven by ' + CAST(Driver AS VARCHAR(MAX)) + ' in Year  ' + CAST(Year AS VARCHAR(MAX))
	FROM Cars a
	WHERE ( a.CarName = b.CarName )
	FOR XML PATH('')
	) ,1,2,'') 
	AS DrivenDetails
FROM Cars b
GROUP BY b.CarName</pre> </p>
<p><strong><code>Please try the different solutions for this puzzle and share it via comment...</code></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/10/sql-puzzle-sql-advance-query-use-stuff-and-form-the-aggregate-of-columns/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
