Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A proper crosstab requires a value for each dimension member. Here's something I made up (see below). You could use this in a Django template like in the doctext example. So you'd issue queries for 1) all Store values, 2) all type_detail values and 3) quantity per store and type_detail. The result of the third query then into a dictionary of (store, type) => quantity.</p> <pre class="lang-python prettyprint-override"><code>class Cube(object): """Iterable sparse cube. Iterating gives an item for every dimension member. &gt;&gt;&gt; pythons = ['eric', 'john', 'terry'] &gt;&gt;&gt; cheeses = ['limburg', 'feta', 'parmigiano'] &gt;&gt;&gt; cheese_consumption = { ('eric', 'limburg'): 2, ('eric', 'parmigiano'): 4, ('john', 'feta'): 5 } &gt;&gt;&gt; cheese_cube = Cube((pythons, cheeses), cheese_consumption) &gt;&gt;&gt; for python, python_cheeses in cheese_cube: for cheese, consumption in python_cheeses: print python, cheese, consumption or 0 eric limburg 2 eric feta 0 eric parmigiano 4 john limburg 0 john feta 5 john parmigiano 0 terry limburg 0 terry feta 0 terry parmigiano 0 """ def __init__(self, dimensions, facts, slice=None): self.dimensions = dimensions self.data_dict = facts self.slice = slice or () def __iter__(self): if len(self.slice) + 1 &lt; len(self.dimensions): for item in self.dimensions[len(self.slice)]: yield item, Cube(self.dimensions, self.data_dict, self.slice + (item,)) else: for item in self.dimensions[len(self.slice)]: yield item, self.data_dict.get(self.slice + (item,), None) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload