<?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>Steve&#039;s Journal &#187; sum</title>
	<atom:link href="http://www.kf8ki.com/tag/sum/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kf8ki.com</link>
	<description>Just another day in paradise...</description>
	<lastBuildDate>Sat, 04 Feb 2012 21:41:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Thought for the Day &#8211; July 21, 2009</title>
		<link>http://www.kf8ki.com/humor/thought-for-the-day-july-21-2009/</link>
		<comments>http://www.kf8ki.com/humor/thought-for-the-day-july-21-2009/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 17:12:29 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Geek Stuff]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sum]]></category>
		<category><![CDATA[thought for the day]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.kf8ki.com/?p=559</guid>
		<description><![CDATA[Computers never do what you want them to do, only what you tell them to do. Unless there&#8217;s a bug. Then you&#8217;re just screwed&#8230; Grrrr&#8230; nothing like a MySql bug to really make your day. I had need to generate &#8230; <a href="http://www.kf8ki.com/humor/thought-for-the-day-july-21-2009/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3 class="UIIntentionalStory_Message">Computers never do what you want them to do, only what you tell them to do. Unless there&#8217;s a bug. Then you&#8217;re just screwed&#8230;</h3>
<p>Grrrr&#8230; nothing like a MySql bug to really make your day.</p>
<p>I had need to generate a sum for a column of duration values with the type of TIME.  Orginally I used this as part of my query:</p>
<p>sum(call_duration) as totalhours</p>
<p>Turns out this does not work properly and has apparently been a problem since 2005!</p>
<p><a href="http://bugs.mysql.com/bug.php?id=12108" target="_blank">http://bugs.mysql.com/bug.php?id=12108</a></p>
<p>From reading the comments, there appears to be some argument as to the validity of the bug.  For what it&#8217;s worth, I found that the problem is more pronounced with more results.  I found that it was non-existant (that is that the sum returned the correct value) with result sets with only a few rows.   The problem seemed to get more severe based on more rows in the results.  In my case, a result set with about 2000 rows in it had an error of on the order of three hours.</p>
<p>The work around is to modify the query slightly:</p>
<p>sum(TIME_TO_SEC(crf_call_duration)) as totalhours</p>
<p>This converts the time to essentially an integer which is then properly handled by the sum.  You can then either work with the result as a count of seconds, or use the function SEC_TO_TIME to convert it back to a TIME value.</p>
<p>I hope this helps someone else.  It cost me a number of hours&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kf8ki.com/humor/thought-for-the-day-july-21-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

