Tableau croisé SQL Pivot Table
Cette page
a été mise à jour le
20 janvier 2009.
Contact |
Versionning :
Vous avez un fichier avec ce genre d'information |
You have a file with this kind of statistic data : |
|
par exemple avec ces données : |
for example, with these values : |
|
un tableau coisé montrera ces colonnes :
La clé de ce rapport est que le nombre de colonnes dépend du nombre de régions ce sql : |
a pivot report will shows colums :
The key of the report is that the number of columns is depending on the number of distinct REGION values this sql : |
|
réponds |
answers : |
|
ce qui donne exactement ce que l'on recherche. Avec ces valeurs clés cela devient facile de construire cette requête |
that are the key we search. With these keys, we can simply construct this string |
|
que l'on utilisera dans un sql
dynamique RPG (modèle : voir sylk21 dans SYLK2)
ou dans un RUNSQLSTL ou un
STRQMQRY
réponse : |
that is to be run as dynamic rpg sql (rpg sample is sylk21 at SYLK2) (or with RUNSQLSTM or with STRQMQRY ...) it answers : |
|
la réponse de SQL400
fait ici plus de 350 caractères de large, ce qui n'est pas
très aisé à utiliser. C'est la raison
pour laquelle vous avez intérêt à
exporter directement au format excel. Je sais, j'aurais pu ajouter
des
fonctions DECIMAL pour raccourcir un peu, mais je
préfère excel.
Il ne manque que le total général. Ce SQL s'en charge |
actual sql400 response width is here 350+ characters, that is not easy to read. It's the reason why you have a better choice to export directly in excel format. Yes, I know I could have added some DECIMAL function, but excel is a better choice. Now the horizontal total is missing. This SQL add the missing line : |
|
réponse : |
it answers |
|
Si vous travaillez en RPG, utilisez deux SQL séparés, c'est plus pratique Si vous travaillez avec STRQMQRY (donc vous devrez compiler le qmqry avant de l'utiliser, par exemple dans QTEMP) pour obtenir le résultat dans un fichier créé à la volée, préférez une union des deux sql ... ou ajoutez un ; (point virgule) entre les deux sql Si vous travaillez avec RUNSQLSTM (donc pas besoin de recompiler), vous devrez ajouter un CREATE avant le premier SQL ... et incorporer vos SELECT dans des INSERT INTO |
If you work within an RPG program, you have a good choice to work with two independant sql select. If you work with a STRQMQRY (ie you have to compile the qmqry before running it, for example in QTEMP) to output the select to a dynamicaly created file, you can have a better choice to run an union of the two sqls. Or run each select separated by a semicolon If you work with RUNSQLSTM (ie you don't want to compile an object), you have to add a sql CREATE before the first select ... and embed the SELECTs into INSERT INTO |
Procédure de test :
c'est comme ça que j'ai construit cette page
|
Test procedure:
it is like that that I constructed this page
|
j'ai construit la démonstration comme ceci : | I have build this demonstration : |
|
ci-après les fichiers correspondants | hereafter the corresponding files |
You are looking for a more classic solution ? go to
The
source code is
provided as an open source tool under the
GNU
General Public License,
version 2.
In summary, this
license specifies:
By clicking the download link you acknowledge and agree to the terms of the license.
last version : The SaveFiles