Bonjour,

J'ai 2 tables de départ :
- TEMP_VOIE avec 2 000 000 d'enregistrements
- TEMP_NUMERO avec 20 000 000 d'enregistrements
(je suis sous postgres 7.3)

je veux migrer ces données dans un table DESTINATION en effectuant les traitements suivants :

pour chaque ligne TEMP_VOIE, il me faut récupere le :
- min des numeros impairs
- max des numeros impairs
- min des numeros pairs
- max des numeros pairs

quelle solution est la plus rapide ?

SOLUTION 1 :

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
 
insert into DESTINATION (CLE, LIBELLE, MIN_IMP, MAX_IMP, MIN_P, MAX_P)
select distinct CLE, LIBELLE,
(
  select  min(a.numero) from TEMP_NUMERO  a where a.CLE = t.CLE
  and a.numero > 0 and a.numero % 2 = 1
  group by a.matricule
),
(
  select  max(a.numero) from TEMP_NUMERO  a where a.CLE = t.CLE
  and a.numero > 0 and a.numero % 2 = 1
  group by a.matricule
),
(
  select  min(a.numero) from TEMP_NUMERO  a where a.CLE = t.CLE
  and a.numero > 0 and a.numero % 2 = 0
  group by a.matricule
),
(
  select  max(a.numero) from TEMP_NUMERO  a where a.CLE = t.CLE
  and a.numero > 0 and a.numero % 2 = 0
  group by a.matricule
)
from TEMP_VOIE t
Je suis oblige de faire 4 sous requetes ...


SOLUTION 2

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
insert into DESTINATION (CLE, LIBELLE, MIN_IMP, MAX_IMP, MIN_P, MAX_P)
select distinct CLE, LIBELLE, min(a.num), max(a.num), 
min(b.num), max(b.num)
from TEMP_VOIE t, TEMP_NUMERO a, TEMP_NUMERO b
and a.CLE = t.cle and a.num >0 and a.num % 2 = 1
and b.CLE = t.cle and b.num >0 and b.num % 2 = 0
group by t.CLE, t.LIBELLE
Je crois que cette solution ne fonctionne pas du fait qu'aucune ligne ne serait au final regroupe, les 2 modulos etant concurrents ?!

Confirmez vous cela ?

J'ai besoin d'avoir les 4 valeurs simultannemets, il y a t-il une autre solution ?
.. avec des CASE ?! je n'arrive pas a les utiliser ...

SOLUTION 3

Le faire en 3 etape :
- je fais un uptade de TEMP_VOIE avec les numeros pairs
- je fais un uptade de TEMP_VOIE avec les numeros impairs
- au final j'insere le tout !!

Que me conseiller vous ?

Merci d'avance.