<?xml version="1.0" encoding="windows-1252"?>
<node id="903867" title="X, Y Table structure" created="2011-05-09 21:04:19" updated="2011-05-09 21:04:19">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;p&gt;I have the following database table structure:&lt;/p&gt;
&lt;pre&gt;
id, size, qty, price
1 ,  1  , 100, 43
2 ,  1  , 250, 52
4 ,  2  , 100, 45
5 ,  2  , 250, 55
6 ,  3  , 100, 50
7 ,  3  , 250, 56
8 ,  4  , 200, 55
9 ,  5  , 250, 61
&lt;/pre&gt;
&lt;p&gt;I am looking to get this kind of output:&lt;/p&gt;
&lt;table border="1"&gt;
&lt;tr&gt;
	&lt;td&gt;&amp;nbsp;&lt;/td&gt;
	&lt;td align="center" colspan="5"&gt;Sizes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;QTY&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;100&lt;/td&gt;&lt;td&gt;$43&lt;/td&gt;&lt;td&gt;$45&lt;/td&gt;&lt;td&gt;$50&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;200&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;$55&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;250&lt;/td&gt;&lt;td&gt;$52&lt;/td&gt;&lt;td&gt;$55&lt;/td&gt;&lt;td&gt;$56&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;$61&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;My thought that this requires three sql selects, 
first two to get distinct values of sizes, qty and the 3rd to build data structure out of it.
&lt;/p&gt;
&lt;p&gt;But I couldn't imagine the data structure that could give me the output shown above.&lt;/p&gt;
&lt;p&gt;Therefore I need your help on the most appropriate solution for this ( the data structure that works best &amp; if this can be done in one sql query ).&lt;/p&gt;
</field>
<field name="reputation">
3</field>
</data>
</node>
