﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / How to reduce the number of table access from multiple "select count(*) group by" with union all / 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>Tue, 18 Jun 2013 22:11:19 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How to reduce the number of table access from multiple "select count(*) group by" with union all</title><link>http://www.sqlservercentral.com/Forums/Topic1423185-392-1.aspx</link><description>That's great...Let me test it out...</description><pubDate>Fri, 22 Feb 2013 14:15:15 GMT</pubDate><dc:creator>Jay Byoun</dc:creator></item><item><title>RE: How to reduce the number of table access from multiple "select count(*) group by" with union all</title><link>http://www.sqlservercentral.com/Forums/Topic1423185-392-1.aspx</link><description>[code="sql"]Select     A, B, C,    sum(case when A between   1 and 100 and B between   1 and 100 and C between   1 and 100 then 1 else 0 end) AS '100',    sum(case when A between 101 and 200 and B between 101 and 200 and C between 101 and 200 then 1 else 0 end) AS '200',    sum(case when A between 201 and 300 and B between 201 and 300 and C between 201 and 300 then 1 else 0 end) AS '300',    sum(case when A &amp;gt; 300 and B &amp;gt; 300 and C &amp;gt; 300 then 1 else 0 end) AS 'Over 300'from SameTablewhere     (A between   1 and 100 and B between   1 and 100 and C between   1 and 100) or    (A between 101 and 200 and B between 101 and 200 and C between 101 and 200) or    (A between 201 and 300 and B between 201 and 300 and C between 201 and 300) or    (A &amp;gt; 300 and B &amp;gt; 300 and C &amp;gt; 300)group by A,B,C[/code]</description><pubDate>Fri, 22 Feb 2013 13:27:46 GMT</pubDate><dc:creator>ScottPletcher</dc:creator></item><item><title>RE: How to reduce the number of table access from multiple "select count(*) group by" with union all</title><link>http://www.sqlservercentral.com/Forums/Topic1423185-392-1.aspx</link><description>This may be way off base but could you add a column to your query and use CASE to populate it based on your A, B &amp; C values? Then you could include that in your GROUP BY.</description><pubDate>Fri, 22 Feb 2013 13:27:17 GMT</pubDate><dc:creator>hslawj</dc:creator></item><item><title>How to reduce the number of table access from multiple "select count(*) group by" with union all</title><link>http://www.sqlservercentral.com/Forums/Topic1423185-392-1.aspx</link><description>I have a select statement as below, which causes a table access for each union all..  My goal is to cut down the number of table access without using union all..Select A, B, C, '100' as CntType, count(*) as Cnt from SameTable where A between 1 and 100 and B between 1 and 100 and C between 1 and 100 group by A,B,CUnion allSelect A, B, C, '200' as CntType, count(*) as Cnt from SameTable where A between 101 and 200 and B between 101 and 200 and C between 101 and 200 group by A,B,CUnion allSelect A, B, C, '300' as CntType, count(*) as Cnt from SameTable where A between 201 and 300 and B between 201 and 300 and C between 201 and 300 group by A,B,CUnion allSelect A, B, C, 'Over 300' as CntType, count(*) as Cnt from SameTable where A &amp;gt; 300 and B &amp;gt; 300 and C &amp;gt; 300 group by A,B,CThe above Union all will access the SameTable four times, I'd like to have SQL statements to access the SameTable once..Please HELP!Happy Friday...</description><pubDate>Fri, 22 Feb 2013 11:31:02 GMT</pubDate><dc:creator>Jay Byoun</dc:creator></item></channel></rss>