Salut !
J'ai deux tables que je relie par jointure dans une requête. Mais l'information que je veux extraire n'est pas la même en terme de date. en effet, chacune des deux tables dispose d'une champ date mais je veux extraire de la table 1 l'info relative à la date n qui correspondant à l'info stockée en n-1 dans la table 2.
y'a pas mieux qu'un exemple dira l'autre
voilà :
toute proposition d'amélioration du code est la bienvenue
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
24
25
26
27
28
29
30
31
32
33
34
35
36 select d.code_unite, d.nom_unite, sum( ( select frais_total from tb_frais_exploitations where tb_frais_exploitations.code_step = b.code_step and tb_frais_exploitations.date_mois between :date_debut and :date_fin ) ) frais_total, sum (c.frais ), sum( a.montant_facture ) montant_facture, sum(( e.volume_mj_sortie ) * (e.nombre_jour_reel) ) volume_mj_sortie, ( sum( c.frais ) + sum( a.montant_facture ) ) frais_total, ( ( sum( c.frais ) + sum ( a.montant_facture ) ) / ( avg (( e.volume_mj_sortie ) * (e.nombre_jour_reel) ) ) ) ratio from tb_energie a inner join tb_step b on (a.code_step = b.code_step) inner join tb_frais_exploitations c on (b.code_step = c.code_step) inner join tb_unite d on (b.code_unite = d.code_unite) inner join tb_process e on (b.code_step = e.code_step) where ( ( e.date_bilan between :date_debut and :date_fin ) and ( c.date_mois between :date_debut and :date_fin ) and ( a.date_mois between :date_debut and :date_fin ) /* c'est ici que je voudrais avoir l'info du mois date_debut - 1mois et date_fin -1mois */ ) group by d.code_unite, d.nom_unite
merci par avance
Partager