
table: pivotedtable

amount   |key1   |key2   |
==========================
10       |one    |un     |
12       |two    |deux   |
13       |one    |deux   |
14       |two    |un     |

create table pivotedtable (amount real, key1 varchar(5), key2 varchar(5));

insert into pivotedtable values (10,'one','un');
insert into pivotedtable values (12,'two','deux');
insert into pivotedtable values (13,'one','deux');
insert into pivotedtable values (12,'two','un');
insert into pivotedtable values (2, 'two','un');


\  key1|one |two |
  \    |    |    |
key2\  |    |    |
======\===========
un     |10  |14  |
deux   |13  |12  |



<!-- dtsHeaders' only purpose is to generate the
     heading across the top.  A little redundant, but
     currently a necessary evil :(  -->
<datasource name="dtsHeaders" distinct="Y" orderby="key1"/>

<!-- Master tables -->
<datasource name="dtsRows" table="pivotedtable" distinct="Y"/>
<datasource name="dtsColumns" table="pivotedtable" distinct="Y"
            master="dtsRows" masterlink="key2" detaillink="key2"
            orderby="key1"/>

<!-- And the pivot table -->
<datasource name="dtsData" table="pivotedtable"
     master="dtsRows" masterlink="key1,key2" detaillink="key1,key2" />





<out:table>


<!-- Spit out the heading line -->
<out:row>
  <out:col>Amount</out:col>
  <section name="header" source="dtsHeaders">
    <out:col><field name="key1">
  </section>
</out:row>


<!-- And the rows... -->
<section name="rows" source="dtsRows">
  <out:row>
    <out:col><field name="key2">
    <section name="cols" source="dtsColumns">
     <section name="data" source="dtsData">
<!--      <out:col><field name="amount" source="dtsRows"/></out:col> -->
      <default>
        <out:col>-0-</out:col>
      </default>
     </section>
     <out:col><summ type="sum" field="amount"/></out:col>
    </section>
  </out:row>
</section>


</out:table>


