 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: SQL sum() with where</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/</link>
	<description></description>
	<lastBuildDate>Mon, 20 May 2013 05:26:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: TomLiotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/#comment-110557</link>
		<dc:creator>TomLiotta</dc:creator>
		<pubDate>Tue, 28 Aug 2012 04:30:04 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/#comment-110557</guid>
		<description><![CDATA[&lt;EM&gt;I dont care how many rows were selected, I just want to know if the condition is true.&lt;/EM&gt;
&#160;
What condition? That sub-SELECT only has one condition -- where wmactc = 0. But I&#039;m pretty sure that&#039;s not the condition that you mean.
&#160;
There might be dozens, hundreds or thousands of rows &quot;where wmactc = 0&quot;. Which one do you want to test against the sum() value? That&#039;s what you need to decide. SQL needs to know which one should be tested to determine if sum(w1actc) is less than that row.
&#160;
Some of the rows might be greater than; some might be less than. If you don&#039;t tell SQL which row to compare against, it has no way to tell when the condition is true.
&#160;
You have a value -- sum(w1actc). And then you have a set of rows -- select w1remc from filea where wmactc = 0. It looks as if you&#039;re trying to compare a single value against a set of values.
&#160;
Let&#039;s say that sum(w1actc) comes out as (5), and your sub-select finds three rows with the values (3, 5, 7). Does that mean that the condition is true or false? It seems it would be both.
&#160;
If you want to know if your sum is less than all of the values, use MIN(w1remc) in your sub-select. Or if you want to know if it&#039;s less than any of the values, use MAX(w1remc).
&#160;
Tom]]></description>
		<content:encoded><![CDATA[<p><em>I dont care how many rows were selected, I just want to know if the condition is true.</em><br />
&nbsp;<br />
What condition? That sub-SELECT only has one condition &#8212; where wmactc = 0. But I&#8217;m pretty sure that&#8217;s not the condition that you mean.<br />
&nbsp;<br />
There might be dozens, hundreds or thousands of rows &#8220;where wmactc = 0&#8243;. Which one do you want to test against the sum() value? That&#8217;s what you need to decide. SQL needs to know which one should be tested to determine if sum(w1actc) is less than that row.<br />
&nbsp;<br />
Some of the rows might be greater than; some might be less than. If you don&#8217;t tell SQL which row to compare against, it has no way to tell when the condition is true.<br />
&nbsp;<br />
You have a value &#8212; sum(w1actc). And then you have a set of rows &#8212; select w1remc from filea where wmactc = 0. It looks as if you&#8217;re trying to compare a single value against a set of values.<br />
&nbsp;<br />
Let&#8217;s say that sum(w1actc) comes out as (5), and your sub-select finds three rows with the values (3, 5, 7). Does that mean that the condition is true or false? It seems it would be both.<br />
&nbsp;<br />
If you want to know if your sum is less than all of the values, use MIN(w1remc) in your sub-select. Or if you want to know if it&#8217;s less than any of the values, use MAX(w1remc).<br />
&nbsp;<br />
Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PietaKit</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/#comment-110554</link>
		<dc:creator>PietaKit</dc:creator>
		<pubDate>Tue, 28 Aug 2012 03:47:27 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/#comment-110554</guid>
		<description><![CDATA[Thanks.I was able to make the select statement work using the having clause. However, it ran into the error of finding more than one row that met the condition &#039;Result of select more than one row&#039;. Is there a way to disregard how many rows were selected with a true/false condition? In other words, I dont care how many rows were selected, I just want to know if the condition is true. ]]></description>
		<content:encoded><![CDATA[<p>Thanks.I was able to make the select statement work using the having clause. However, it ran into the error of finding more than one row that met the condition &#8216;Result of select more than one row&#8217;. Is there a way to disregard how many rows were selected with a true/false condition? In other words, I dont care how many rows were selected, I just want to know if the condition is true. </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/#comment-110553</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Tue, 28 Aug 2012 03:12:56 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/sql-sum-with-where/#comment-110553</guid>
		<description><![CDATA[You can&#039;t use aggregate functions in the WHERE clause.

Take a look at the &lt;a href=&quot;http://www.techonthenet.com/sql/having.php&quot; rel=&quot;nofollow&quot;&gt;HAVING clause&lt;/a&gt;.]]></description>
		<content:encoded><![CDATA[<p>You can&#8217;t use aggregate functions in the WHERE clause.</p>
<p>Take a look at the <a href="http://www.techonthenet.com/sql/having.php" rel="nofollow">HAVING clause</a>.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/8 queries in 0.010 seconds using memcached
Object Caching 297/298 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-20 06:51:51 -->