﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Gregory Larsen / Article Discussions / Article Discussions by Author  / Stairway to T-SQL DML Level 7: Summarizing Data Using a Simple GROUP BY Clause / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 00:27:32 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Stairway to T-SQL DML Level 7: Summarizing Data Using a Simple GROUP BY Clause</title><link>http://www.sqlservercentral.com/Forums/Topic1205128-90-1.aspx</link><description>Good article...One comment though...I would not filter on a row value in a having statement, the code is wasting CPU cycles and too much memory swapping.The last example would be an illustration of that.SELECT StoreName      ,SUM(TotalSalesAmount) AS StoreSalesAmountFROM dbo.SalesTransaction GROUP BY StoreName HAVING StoreName LIKE '%Outlet%'     &amp;lt;==== NOT GOOD    OR StoreName LIKE '%Books%';This should be better written like:SELECT StoreName      ,SUM(TotalSalesAmount) AS StoreSalesAmountFROM dbo.SalesTransaction WHERE StoreName LIKE '%Outlet%'    &amp;lt;=== This way the row is not even loaded in to memory to be aggregated.    OR StoreName LIKE '%Books%';GROUP BY StoreName </description><pubDate>Wed, 04 Jan 2012 07:57:08 GMT</pubDate><dc:creator>Tim Curtin</dc:creator></item><item><title>RE: Stairway to T-SQL DML Level 7: Summarizing Data Using a Simple GROUP BY Clause</title><link>http://www.sqlservercentral.com/Forums/Topic1205128-90-1.aspx</link><description>I noticed an interesting feature when I do "Grouping by Two Columns" on table with PrimaryKey (Clustered Index Unique):select ProductID,Shelf,sum(Quantity)from Production.ProductInventory group by ProductID,ShelfIn this case, the result is automatically sorted by the second column from GroupBy clause “Shelf”. Is not that strange? In certain situations, the ExecutionPlan shows that SQL Engne executes the illogical/invert sort. Why executes any sort?This is not the case when we do "Grouping by Tree Columns or More".</description><pubDate>Wed, 04 Jan 2012 03:14:04 GMT</pubDate><dc:creator>bojan.jekic 78340</dc:creator></item><item><title>Stairway to T-SQL DML Level 7: Summarizing Data Using a Simple GROUP BY Clause</title><link>http://www.sqlservercentral.com/Forums/Topic1205128-90-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/Stairway+Series/75779/"&gt;Stairway to T-SQL DML Level 7: Summarizing Data Using a Simple GROUP BY Clause&lt;/A&gt;[/B]</description><pubDate>Mon, 14 Nov 2011 07:22:42 GMT</pubDate><dc:creator>Greg Larsen</dc:creator></item></channel></rss>