Обсуждение: Crosstab Question

Поиск
Список
Период
Сортировка

Crosstab Question

От
David Blewett
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi All:

I'm building an application along the lines of the questionnaire
design on varlena.com [1], with slight modifications. In my design,
there's a table called chartversionquestion that collects different
questions into a bundle to create the questionnaire.

Using a view [2] very similar to the one on varlena, I pull all the
data from the value tables into one long list (cast to text). I
would like to be able to create a crosstab from this view such that
the short question name becomes a column header, with the related
value underneath.

Since the number of questions to be pivoted will vary per
questionnaire the method should accept a number of columns
parameter. The crosstab in the tablefunc contrib module expects the
columns to be explicitly identified before hand. I suppose it could
be possible to write a simple function to wrap the crosstab_n_cols
functions to be able to return a variable number, but that seems
hackish. Are there any other alternatives?

David Blewett

[1] http://www.varlena.com/GeneralBits/110.php
[2] http://www.varlena.com/varlena/GeneralBits/Tidbits/QnA/views.sql
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGul6MZmlc6wNjtLYRCA5hAJ9fSHjNI5gQs/eqZ85bHl4ZrGWG3ACfbEnG
zo1KFvZL8LraBESRySyVryg=
=w1Z8
-----END PGP SIGNATURE-----

Re: Crosstab Question

От
Michael Glaesemann
Дата:
On Aug 8, 2007, at 19:23 , David Blewett wrote:

> Since the number of questions to be pivoted will vary per
> questionnaire the method should accept a number of columns
> parameter. The crosstab in the tablefunc contrib module expects the
> columns to be explicitly identified before hand. I suppose it could
> be possible to write a simple function to wrap the crosstab_n_cols
> functions to be able to return a variable number, but that seems
> hackish. Are there any other alternatives?

I've done just that in the past. It's pretty straightforward and has
worked fine.

Michael Glaesemann
grzm seespotcode net



Вложения