<?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>Cale Dunlap &#187; confusion</title>
	<atom:link href="http://www.caledunlap.com/tag/confusion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.caledunlap.com</link>
	<description>Programmer and hobbyist game developer</description>
	<lastBuildDate>Fri, 20 Aug 2010 08:13:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>1 little 2 little 3 little endians&#8230; er wait, is it 3 little 2 little 1 little endians?</title>
		<link>http://www.caledunlap.com/2009/06/1-little-2-little-3-little-endians-er-wait-is-it-3-little-2-little-1-littl-endians/</link>
		<comments>http://www.caledunlap.com/2009/06/1-little-2-little-3-little-endians-er-wait-is-it-3-little-2-little-1-littl-endians/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 17:50:42 +0000</pubDate>
		<dc:creator>Cale</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development Journal]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[confusion]]></category>

		<guid isPermaLink="false">http://caledunlap.com/blog/?p=286</guid>
		<description><![CDATA[Well, it depends on what]]></description>
			<content:encoded><![CDATA[<p>Well, it depends on what encoding you&#8217;re using.</p>
<p>Lately I&#8217;ve been in &#8220;endian-ness&#8221; hell on a project I&#8217;m working on. Well, not really a &#8220;hell&#8221;, more of a hurdle that can easily be overcome. A friend of mine recently asked me the difference between the two binary encoding strategies and when I went to explain it to him (via cell phone txt messaging) I quickly realized that I will run up both our bills pretty quickly by doing so. So here&#8217;s the quick rundown, and an example as it applies to the project I am working on.</p>
<p>Big Endian means that value is stored &#8220;from left to right&#8221;. The most significant values (bytes) are stored in memory with the lowest address first. This is probably what many people are familiar with, especially those in the networking field.  Here&#8217;s an example of data stored as Big Endian:</p>
<p>Take for instance the 2-byte value 1325, equivalent to a short or unsigned short. Stored in Big Endian encoding, the value would look like this in binary: 00000101 00101101. Makes sense right?</p>
<p>Now here is the same 2-byte value, 1325, in Little Endian encoding: 00101101 00000101. The bytes are flipped and thus to make any sense of it, you must read the last set of bits first.</p>
<p>So for simplicity&#8217;s sake, Big Endian values are stored like so:</p>
<pre>&lt;byte1&gt; &lt;byte2&gt; &lt;byte3&gt; &lt;byte4&gt; ... &lt;byten&gt;</pre>
<p>Little Endian values are stored like so:</p>
<pre>&lt;byten&gt; ... &lt;byte4&gt; &lt;byte3&gt; &lt;byte2&gt; &lt;byte1&gt;</pre>
<p>Network devices use Big Endian, it is considered the network standard, or &#8220;network encoding&#8221;. Endian-ness varies from CPU to CPU depending on its architecture. <strong>Power</strong> Macs use Big Endian, network devices use Big Endian. Intel PC&#8217;s (and <strong>Intel</strong> Macs) use Little Endian. What does that mean? Well, it means that if a program running on a <strong>Power</strong> Mac sends data to a PC, the PC may not understand it correctly without some type of encoding change taking place.</p>
<p>In my situation, I&#8217;m reading a series of values off of the network, all coming in via a byte stream. So the client will send the following packet for example:</p>
<p>4 bytes, 2 bytes, 1 byte, &#8230; and some others but I won&#8217;t get into them</p>
<p>So when I read the first four bytes off the network (which uses Big Endian encoding, remember?) I must flip the entire set of 4 bytes before my Little Endian PC can understand it.  Same goes for the next 2 bytes. The single byte obviously doesn&#8217;t need to be flipped with anything, it stands alone. So an incoming set of data may look like:</p>
<pre>0x1A 0x2B 0x3C 0x4D 0x2A 0x2B 0xAD</pre>
<p>Now I must flip each set of values byte by byte (but not invert the entire thing; this is a packet, containing multiple values).</p>
<p>In Little Endian, the same set of data reads:</p>
<pre>0x4D 0x3C 0x2B 0x1A 0x2B 0x2A 0xAD</pre>
<p>Confused yet? You&#8217;ll figure it out. Here&#8217;s some reading that should help: <a href="http://en.wikipedia.org/wiki/Endianness">http://en.wikipedia.org/wiki/Endianness</a>. It even gets into the origins of the word, which is pretty interesting. Here&#8217;s a little tool that may help you understand the pattern: <a href="http://dlnova.com/reverseendian.htm">http://dlnova.com/reverseendian.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.caledunlap.com/2009/06/1-little-2-little-3-little-endians-er-wait-is-it-3-little-2-little-1-littl-endians/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross-Tabulation (Pivot Tables) with MySQL</title>
		<link>http://www.caledunlap.com/2009/02/cross-tabulation-pivot-tables-with-mysql/</link>
		<comments>http://www.caledunlap.com/2009/02/cross-tabulation-pivot-tables-with-mysql/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 10:09:14 +0000</pubDate>
		<dc:creator>Cale</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Development Journal]]></category>
		<category><![CDATA[confusion]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pivot tables]]></category>
		<category><![CDATA[tabulation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://caledunlap.com/blog/?p=191</guid>
		<description><![CDATA[I don&#8217;t really have any]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t really have any sections on my website related to MySQL, so I figured I&#8217;d just throw together a quick post about something I found incredibly helpful. I&#8217;m sure others will find it nice too.</p>
<p>So in my years being trained on data architecture and database design, I learned to &quot;normalize, normalize, normalize&quot;. Unfortunately, normalization doesn&#8217;t lend itself to very simple statistical calculations&#8211;such as those used to generate graphs or a statistical scorecard.</p>
<p>In the case of Angel, I&#8217;ve normalized the hell out of the data. Now it comes down to needing to report on that data. At first, my reporting attempts were terrible&#8211;tons of nested loops, many queries, etc. Well, when I spoke to a colleague of mine at work, he said that if I was running on an SAS Mainframe, the work would already be done for me using a function called &quot;PROC TABULATE&quot;. He sort of dated himself by saying that.</p>
<p>Then I broke the news to him: I&#8217;m not using SAS, or any other mainframe technology. He replied by suggesting I look into some sort of MySQL equivalent to that function. So I started hunting. I came across this very nice article: <a href="http://dev.mysql.com/tech-resources/articles/wizard/print_version.html" target="_blank">http://dev.mysql.com/tech-resources/articles/wizard/print_version.html</a></p>
<p>That article shows, very effectively, how to create a nice &quot;statistical&quot; report using cross-tabulation techniques with normalized source data. The queries are sort of monstrous if you have a large number of fields to report on, but at that point, you&#8217;d be using code to generate the parameters for the SELECT statement.</p>
<p>Here&#8217;s my example:</p>
<p>My source data looks like the following&#8211;please note that some results are truncated because the result set would be WAY too large for a blog:</p>
<p> <code>
<pre>mysql&gt; select uid, Email from players;
+-----+--------------------------+
| uid | Email                    |
+-----+--------------------------+
|  10 | brian@venomgamelabs.com  |
|   4 | cale@caledunlap.com      |
|   1 | cale@venomgamelabs.com   |
|   9 | daniel@venomgamelabs.com |
|  11 | dave@venomgamelabs.com   |
|   5 | jane@venomgamelabs.com   |
|   8 | janes@venomgamelabs.com  |
|  12 | jill@venomgamelabs.com   |
|   6 | john@venomgamelabs.com   |
|   7 | johns@venomgamelabs.com  |
+-----+--------------------------+
mysql&gt; select * from gamedata LIMIT 10;
+----------+---------+------+
| playerid | fieldid | data |
+----------+---------+------+
|        1 |       3 | 60   |
|        1 |       4 | 1    |
|        1 |       5 | 1    |
|        1 |       6 | 286  |
|        1 |       7 | 1    |
|        1 |       8 | 13   |
|        1 |       9 | 1    |
|        1 |      10 | 1    |
|        1 |      11 | 261  |
|        1 |      12 | 13   |
+----------+---------+------+

mysql&gt; select FieldID, FriendlyName, GameID, FieldTypeID FROM gamefields;
+---------+---------------------------------+--------+-------------+
| FieldID | FriendlyName                    | GameID | FieldTypeID |
+---------+---------------------------------+--------+-------------+
|       1 | Play Time                       |      1 |           2 |
|       2 | Last Character                  |      1 |           1 |
|       3 | Total Eggs                      |      4 |           2 |
|       4 | Total Playtime                  |      4 |           2 |
|       5 | Total King Of The Hill Captures |      4 |           2 |
|       6 | Total Kills                     |      4 |           2 |
|       7 | Total Deaths                    |      4 |           2 |
|       8 | Engineer Playtime               |      4 |           2 |
|      10 | Mongo Playtime                  |      4 |           2 |
|      11 | Grunt Playtime                  |      4 |           2 |
|      12 | Gladiator Playtime              |      4 |           2 |
|      13 | Total Powerup Uses              |      4 |           2 |
|      14 | Total Powerups Received         |      4 |           2 |
+---------+---------------------------------+--------+-------------+
mysql&gt; select typeid, typename from field_types;
+--------+------------------+
| typeid | typename         |
+--------+------------------+
|      1 | Text             |
|      2 | Numeric          |
|      3 | Game Coordinates |
|      4 | Boolean          |
|      5 | Physical Address |
|      6 | IP Address       |
+--------+------------------+</pre>
<p></code></p>
<p>What I want to know from that data is how many players have field values within specific ranges&#8211;to generate some input data for a chart output. The code I&#8217;m using does the following math (from a separate query):</p>
<ol>
<li>Find the minimum value out of all of the player data for each field (SQL Query) </li>
<li>Find the maximum value out of all of the player data for each field (Same SQL query) </li>
<li>Get a &quot;standard deviation&quot; between the number <code>$StandardDeviation = floor( ($High - $Low)/NUM_DEVIATION_RANGES );</code> </li>
<li>Begins a SQL query and assembles a list of parameters to select (based on the deviation ranges) <code>
<pre>for $i = 0 to NUM_DEVIATION_RANGES
$Min = $Low + ($StandardDeviation * $i)
$Max = ($Min + $StandardDeviation) – 1;
$Query .= “SUM( IF( CAST(gamedata.Data AS UNSIGNED) &gt;= $Min AND CAST(gamedata.Data AS UNSIGNED) &lt;= $Max, 1, 0) ) AS ‘$Min-$Max’,”;
end for</pre>
<p>    </code></li>
<li>Runs the query, obtains a single result per field and feeds it to the chart to render a per-field graphical analysis chart. </li>
</ol>
<p>The output of the query from step 4 is as follows:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0d8710e5-306b-41bd-9c98-3e3cec81dfee" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#0000ff">SELECT</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 60 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 87<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;60-87&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 88 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 115<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;88-115&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 116 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 143<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;116-143&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 144 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 171<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;144-171&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 172 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 199<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;172-199&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 200 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 227<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;200-227&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 228 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 255<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;228-255&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 256 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 283<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;256-283&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 284 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 311<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;284-311&#39;</span><span style="color:#808080">,</span><br />
&#160;&#160;&#160;&#160;<span style="color:#ff00ff">SUM</span><span style="color:#808080">(</span> <span style="color:#0000ff">IF</span><span style="color:#808080">(</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&gt;=</span> 312 <span style="color:#808080">AND</span> <span style="color:#ff00ff">CAST</span><span style="color:#808080">(</span>gamedata<span style="color:#808080">.</span>Data <span style="color:#0000ff">AS</span> UNSIGNED<span style="color:#808080">)</span> <span style="color:#808080">&lt;=</span> 339<span style="color:#808080">,</span>1<span style="color:#808080">,</span>0<span style="color:#808080">)</span> <span style="color:#808080">)</span> <span style="color:#0000ff">AS</span> <span style="color:#ff0000">&#39;312-339&#39;</span><br />
<span style="color:#0000ff">FROM</span> gamedata<span style="color:#808080">,</span> gamefields<span style="color:#808080">,</span> field_types<br />
<span style="color:#0000ff">WHERE</span> gamedata<span style="color:#808080">.</span>fieldid <span style="color:#808080">=</span> gamefields<span style="color:#808080">.</span>FieldID<br />
&#160;&#160;&#160;&#160;<span style="color:#808080">AND</span> gamefields<span style="color:#808080">.</span>FieldTypeID <span style="color:#808080">=</span> field_types<span style="color:#808080">.</span>typeid<br />
&#160;&#160;&#160;&#160;<span style="color:#808080">AND</span> field_types<span style="color:#808080">.</span>typename <span style="color:#808080">=</span> <span style="color:#ff0000">&#39;Numeric&#39;</span><br />
&#160;&#160;&#160;&#160;<span style="color:#808080">AND</span> gamefields<span style="color:#808080">.</span>FriendlyName <span style="color:#808080">=</span> <span style="color:#ff0000">&#39;Total Eggs&#39;</span></div>
</div>
</div>
<p>Now that query runs once per number of fields requested. The above query was just a single query for a single field. Note how the code generated the SELECT statement parameters (min and max) and set them as the column header in the result?</p>
<p>The result of that query looks like this:</p>
<p><code></p>
<pre>+-------+--------+---------+---------+---------+---------+---------+---------+---------+---------+
| 60-87 | 88-115 | 116-143 | 144-171 | 172-199 | 200-227 | 228-255 | 256-283 | 284-311 | 312-339 |
+-------+--------+---------+---------+---------+---------+---------+---------+---------+---------+
|     2	|      0 |	 2 |	   0 |	     1 |      0	 |	2  |	   0 |	     1 |       0 |
+-------+--------+---------+---------+---------+---------+---------+---------+---------+---------+</pre>
<p></code></p>
<p>So the output is exactly what I need for my chart. The result fields represent the X axis of the chart, and the result values represent the Y axis of the chart, all from a single query against normalized data using cross-tabulation.</p>
<p>I urge you to click on the link I mentioned near the top of the article if you want to learn how to do this. My example is fairly specific to my situation. That article showed me exactly what I needed to do, but I needed to apply it to my data and my reports.&#160; You&#8217;ll notice that I&#8217;ve used CAST&#8217;s in my query. The reason being that in order to accept any type of data, I&#8217;ve used the &#8216;TEXT&#8217; type on my game data fields&#8211;that&#8217;s why I also have a type table and a type ID in the field types. I then query what types of fields is numeric, and only perform my calculations against them.</p>
<p>Doing cross-tabluation/pivot tables isn&#8217;t too bad once you know what you&#8217;re doing. I had a tough time wrapping my head around it, but after a few hours of tinkering, I finally got what I was looking for. Another thing to note is that I&#8217;m summing up 1&#8242;s and 0&#8242;s, basically a tally. If you want to sum up your real data, don&#8217;t use 1&#8242;s and 0&#8242;s; use your actual data field.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caledunlap.com/2009/02/cross-tabulation-pivot-tables-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
