Bonjour,
J'ai une requête qui va chercher des données dans 2 tables. Une est la table courante, l'autre contient l'historique, donc structure identique + date de l'historique.

Je ne sais pas trop comment expliquer ce que j'aimerais.
En fait avec ces tables, je fais des totaux de montants en fonction de la date.
Par ex, le mois dejuin est dans la table active et les anciennes dates sont dans la table historique.
Je cherche a afficher un tableau récapitulatif des montants par date, par mois et par personne.
Ma requête est la suivante (ca fait un tableau croisé en plus):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SELECT   bill_manager,
              em_id,
              tel_id,
              TO_CHAR (date_invoice_start, 'YYYY'),
              NVL ( MAX (DECODE (date_invoice_start, TO_DATE ('1', 'MM'), total_tva) ), 0 ) Jan,
              NVL (MAX (DECODE (date_invoice_start, TO_DATE ('2', 'MM'), total_tva) ), 0 )  Fev
 
       FROM   taxe_gsm
       group by bill_manager,em_id,tel_id, TO_CHAR date_invoice_start, 'YYYY')
 
   UNION ALL
     SELECT   bill_manager,
              em_id,
              tel_id,
              TO_CHAR (date_invoice_start, 'YYYY'),
              NVL ( MAX (DECODE (date_invoice_start, TO_DATE ('1', 'MM'), total_tva) ), 0 ) Jan,
              NVL (MAX (DECODE (date_invoice_start, TO_DATE ('2', 'MM'), total_tva) ), 0 )  Fev
 
       FROM   htaxe_gsm
   GROUP BY   bill_manager,
              em_id,
              tel_id,
              TO_CHAR (date_invoice_start, 'YYYY')
Mon résultat donne:

bill_manager | em-id | tel_id | TO_CHAR (date_invoice_start, 'YYYY') |JAN | FEV

"le chef" | "l'employer" | 02342342342 | 2010 | 10.07 | 0
"le chef" | "l'employer" | 02342342342 | 2010 | 0 |50.2


Et ce que j'aimerais obtenir est:
bill_manager | em-id | tel_id | TO_CHAR (date_invoice_start, 'YYYY') |JAN | FEV | CUMUL

"le chef" | "l'employer" | 02342342342 | 2010 | 10.07 | 50.2 | 60.27

J'espère que vous m'avez comrpis et que vous pourrez m'aider..