IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQL Oracle Discussion :

optimisation case when


Sujet :

SQL Oracle

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 23
    Points : 10
    Points
    10
    Par défaut optimisation case when
    Bonjour, me voici avec un nouveau problème, en effet dans une requête dans le select j'ai:

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    SUM(CASE
        WHEN indicateur = 'Total traitées' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Total traitées' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Total traitées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Total réglées' and unite = 'Nombre' then s1_nbr_paid
        WHEN indicateur = 'Total réglées' and unite = 'Montant' then s1_mnt_tt_paid
        WHEN indicateur = 'Total réglées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont retard' and unite = 'Nombre' then s1_nb_p_late
        WHEN indicateur = 'Dont retard' and unite = 'Montant' then s1_mnt_p_late
        WHEN indicateur = 'Dont retard' and unite = 'Pourcentage' then CASE WHEN s1_mnt_tt_paid <> 0 THEN s1_nb_p_late/s1_mnt_tt_paid ELSE 0 END
        WHEN indicateur = 'Acquisition' and unite = 'Nombre' then s1_nbr_acq
        WHEN indicateur = 'Acquisition' and unite = 'Montant' then s1_mnt_tt_acq
        WHEN indicateur = 'Acquisition' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont manuelles' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'ONL' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont manuelles' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'ONL' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont manuelles' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont EDI' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'EDI' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont EDI' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'EDI' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont EDI' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont Numérisation' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'NUM' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont Numérisation' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'NUM' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont Numérisation' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Pièces imputées' and unite = 'Nombre' then s1_nbr_acct
        WHEN indicateur = 'Pièces imputées' and unite = 'Montant' then s1_mnt_tt_acct
        WHEN indicateur = 'Pièces imputées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont directement imputables' and unite = 'Nombre' then s1_nbr_dir_imp
        WHEN indicateur = 'Dont directement imputables' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont directement imputables' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Nombre' then s1_nbr_mtch
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Montant' then s1_mnt_tt_mtch
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont directement rapprochées' and unite = 'Nombre' then s1_nbr_dir_rap
        WHEN indicateur = 'Dont directement rapprochées' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont directement rapprochées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Pièces approuvées' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Pièces approuvées' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Pièces approuvées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont directement BAP' and unite = 'Nombre' then s1_nb_auto
        WHEN indicateur = 'Dont directement BAP' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont directement BAP' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Commandes' and unite = 'Nombre' then CASE WHEN S1_PO_FLG = '1' THEN s1_nbr_appr ELSE 0 END
        WHEN indicateur = 'Commandes' and unite = 'Montant' then CASE WHEN S1_PO_FLG = '1' THEN s1_mnt_tt_appr ELSE 0 END
        WHEN indicateur = 'Commandes' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont en régularisation' and unite = 'Nombre' then s1_nb_regul
        WHEN indicateur = 'Dont en régularisation' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont en régularisation' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Réceptions' and unite = 'Nombre' then s1_nbr_acq
        WHEN indicateur = 'Réceptions' and unite = 'Montant' then s1_mnt_tt_acq
        WHEN indicateur = 'Réceptions' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont saisies en retard' and unite = 'Nombre' then s1_nb_rcpt_sup
        WHEN indicateur = 'Dont saisies en retard' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont saisies en retard' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Rapprochement' and unite = 'Nombre' then s1_nbr_mtch
        WHEN indicateur = 'Rapprochement' and unite = 'Montant' then s1_mnt_tt_mtch
        WHEN indicateur = 'Rapprochement' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont exception de rapprochement' and unite = 'Nombre' then s1_nbr_mtch-s1_nb_ss_except
        WHEN indicateur = 'Dont exception de rapprochement' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont exception de rapprochement' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont existence R500' and unite = 'Nombre' then CASE WHEN S1_R500_FLG = '1' THEN S1_NBR_MTCH ELSE 0 END
        WHEN indicateur = 'Dont existence R500' and unite = 'Montant' then CASE WHEN S1_R500_FLG = '1' THEN S1_MNT_TT_MTCH ELSE 0 END
        WHEN indicateur = 'Dont existence R500' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Approbation' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Approbation' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Approbation' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Nombre' then 0
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Pourcentage' then 0
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Nombre' then CASE WHEN mnt.s1_borne_inf < 300 THEN s1_nbr_appr ELSE 0 END
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Montant' then CASE WHEN mnt.s1_borne_inf < 300 THEN s1_mnt_tt_appr ELSE 0 END
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Pièces acheminées' and unite = 'Nombre' then s1_nbr_created
        WHEN indicateur = 'Pièces acheminées' and unite = 'Montant' then 0
        WHEN indicateur = 'Pièces acheminées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Approbation' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Approbation' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Approbation' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont délai < 15 jours' and unite = 'Nombre' then s1_nb_ach_15
        WHEN indicateur = 'Dont délai < 15 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai < 15 jours' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont délai entre 15 et 30 jours' and unite = 'Nombre' then s1_nb_ach_30
        WHEN indicateur = 'Dont délai entre 15 et 30 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai entre 15 et 30 jours' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont délai entre 30 et 45 jours' and unite = 'Nombre' then s1_nb_ach_45
        WHEN indicateur = 'Dont délai entre 30 et 45 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai entre 30 et 45 jours' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont délai entre 45 et 60 jours' and unite = 'Nombre' then s1_nb_ach_60
        WHEN indicateur = 'Dont délai entre 45 et 60 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai entre 45 et 60 jours' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont délai > 60 jours' and unite = 'Nombre' then s1_nb_ach_60
        WHEN indicateur = 'Dont délai > 60 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai > 60 jours' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Pièces payées' and unite = 'Nombre' then s1_nbr_paid
        WHEN indicateur = 'Pièces payées' and unite = 'Montant' then s1_mnt_tt_paid
        WHEN indicateur = 'Pièces payées' and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Nombre' then 0
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Montant' then s1_penal_amt
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Pourcentage' then 1
        ELSE 0 
      END) as valeur
    Mais c'est ultra long, ça alourdi énormément la requête, et j'aimerai savoir si il y a une autre solution (autre que des decode et des case when) afin d'optimiser un peu tout ça.

    Peu être avec du pl/sql ou des fonction oracle j'en sais rien par contre je n'ai pas le droit de créer de type, de tables ... (juste des droits en consultation)

    Merci d'avance.

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    bon déjà en regardant la requête de plus près j'ai remarqué qu les testes étaient fait en double pour l'indicateur 'Approbation' j'ai donc supprimé le doublon et de plus qu'a chaque fois que l'unité est un pourcentage alors on a 1 sauf dans deux cas celui d'indicateur ='dont retard' et 'dont approbation après échéance' donc j'ai regroupé tout ces when en
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WHEN indicateur not in ('Dont retard','Dont approbation après échéance') and unite = 'Pourcentage' then 1
    ce qui donne encore a optimiser :

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    SUM(CASE
        WHEN indicateur not in ('Dont retard','Dont approbation après échéance') and unite = 'Pourcentage' then 1
        WHEN indicateur = 'Total traitées' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Total traitées' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Total réglées' and unite = 'Nombre' then s1_nbr_paid
        WHEN indicateur = 'Total réglées' and unite = 'Montant' then s1_mnt_tt_paid
        WHEN indicateur = 'Dont retard' and unite = 'Nombre' then s1_nb_p_late
        WHEN indicateur = 'Dont retard' and unite = 'Montant' then s1_mnt_p_late
        WHEN indicateur = 'Dont retard' and unite = 'Pourcentage' then CASE WHEN s1_mnt_tt_paid <> 0 THEN s1_nb_p_late/s1_mnt_tt_paid ELSE 0 END
        WHEN indicateur = 'Acquisition' and unite = 'Nombre' then s1_nbr_acq
        WHEN indicateur = 'Acquisition' and unite = 'Montant' then s1_mnt_tt_acq
        WHEN indicateur = 'Dont manuelles' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'ONL' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont manuelles' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'ONL' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont EDI' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'EDI' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont EDI' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'EDI' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont Numérisation' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'NUM' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont Numérisation' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'NUM' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Pièces imputées' and unite = 'Nombre' then s1_nbr_acct
        WHEN indicateur = 'Pièces imputées' and unite = 'Montant' then s1_mnt_tt_acct
        WHEN indicateur = 'Dont directement imputables' and unite = 'Nombre' then s1_nbr_dir_imp
        WHEN indicateur = 'Dont directement imputables' and unite = 'Montant' then 0
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Nombre' then s1_nbr_mtch
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Montant' then s1_mnt_tt_mtch
        WHEN indicateur = 'Dont directement rapprochées' and unite = 'Nombre' then s1_nbr_dir_rap
        WHEN indicateur = 'Dont directement rapprochées' and unite = 'Montant' then 0
        WHEN indicateur = 'Pièces approuvées' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Pièces approuvées' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Dont directement BAP' and unite = 'Nombre' then s1_nb_auto
        WHEN indicateur = 'Dont directement BAP' and unite = 'Montant' then 0
        WHEN indicateur = 'Commandes' and unite = 'Nombre' then CASE WHEN S1_PO_FLG = '1' THEN s1_nbr_appr ELSE 0 END
        WHEN indicateur = 'Commandes' and unite = 'Montant' then CASE WHEN S1_PO_FLG = '1' THEN s1_mnt_tt_appr ELSE 0 END
        WHEN indicateur = 'Dont en régularisation' and unite = 'Nombre' then s1_nb_regul
        WHEN indicateur = 'Dont en régularisation' and unite = 'Montant' then 0
        WHEN indicateur = 'Réceptions' and unite = 'Nombre' then s1_nbr_acq
        WHEN indicateur = 'Réceptions' and unite = 'Montant' then s1_mnt_tt_acq
        WHEN indicateur = 'Dont saisies en retard' and unite = 'Nombre' then s1_nb_rcpt_sup
        WHEN indicateur = 'Dont saisies en retard' and unite = 'Montant' then 0
        WHEN indicateur = 'Rapprochement' and unite = 'Nombre' then s1_nbr_mtch
        WHEN indicateur = 'Rapprochement' and unite = 'Montant' then s1_mnt_tt_mtch
        WHEN indicateur = 'Dont exception de rapprochement' and unite = 'Nombre' then s1_nbr_mtch-s1_nb_ss_except
        WHEN indicateur = 'Dont exception de rapprochement' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont existence R500' and unite = 'Nombre' then CASE WHEN S1_R500_FLG = '1' THEN S1_NBR_MTCH ELSE 0 END
        WHEN indicateur = 'Dont existence R500' and unite = 'Montant' then CASE WHEN S1_R500_FLG = '1' THEN S1_MNT_TT_MTCH ELSE 0 END
        WHEN indicateur = 'Approbation' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Approbation' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Nombre' then 0
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Pourcentage' then 0
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Nombre' then CASE WHEN mnt.s1_borne_inf < 300 THEN s1_nbr_appr ELSE 0 END
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Montant' then CASE WHEN mnt.s1_borne_inf < 300 THEN s1_mnt_tt_appr ELSE 0 END
        WHEN indicateur = 'Pièces acheminées' and unite = 'Nombre' then s1_nbr_created
        WHEN indicateur = 'Pièces acheminées' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai < 15 jours' and unite = 'Nombre' then s1_nb_ach_15
        WHEN indicateur = 'Dont délai < 15 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai entre 15 et 30 jours' and unite = 'Nombre' then s1_nb_ach_30
        WHEN indicateur = 'Dont délai entre 15 et 30 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai entre 30 et 45 jours' and unite = 'Nombre' then s1_nb_ach_45
        WHEN indicateur = 'Dont délai entre 30 et 45 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai entre 45 et 60 jours' and unite = 'Nombre' then s1_nb_ach_60
        WHEN indicateur = 'Dont délai entre 45 et 60 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Dont délai > 60 jours' and unite = 'Nombre' then s1_nb_ach_60
        WHEN indicateur = 'Dont délai > 60 jours' and unite = 'Montant' then 0
        WHEN indicateur = 'Pièces payées' and unite = 'Nombre' then s1_nbr_paid
        WHEN indicateur = 'Pièces payées' and unite = 'Montant' then s1_mnt_tt_paid
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Nombre' then 0
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Montant' then s1_penal_amt
        ELSE 0 
      END) as valeur

  3. #3
    Modérateur
    Avatar de Waldar
    Homme Profil pro
    Customer Success Manager @Vertica
    Inscrit en
    Septembre 2008
    Messages
    8 452
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Customer Success Manager @Vertica
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2008
    Messages : 8 452
    Points : 17 820
    Points
    17 820
    Par défaut
    Vous additionnez quantité, montant et pourcentage ?

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    Non, en gros si j'ai bien compris la requête, ca test l'indicateur et l'unité en fonction de l'indicateur et de l'unité on renvoi quelque chose 1,0 ou une colone et c'est ce qu'on renvoi qui est sommé (1,0 ou la colonne).

    Et le problème je pense qui fait que c'est ultra long, c'est que pour chaque record on test tous ces cas pour savoir ou on est et quoi faire.

    ps: je ne suis pas un expert bdd donc excusez moi si je suis pas très clair dans mes explications


    J'ai regroupé une partie des test de montant dans le cas ou il donne 0 aussi, mais est ce que vraiment j'ay gagne en remplaçant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    when indicateur ='qqchos1' and unité ='qqchose2' then 0
    when indicateur ='qqchos3' and unité ='qqchose2' then 0
    when indicateur ='qqchos4' and unité ='qqchose2' then 0
    when indicateur ='qqchos5' and unité ='qqchose2' then 0
    ...
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    when indicateur in ('qqchose1','qqchose3','qqchose4','qqchose5') and unité='qqchose2' then 0

    j'en suis là avec mon code initial:

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    SUM(CASE
        WHEN indicateur not in ('Dont retard','Dont approbation après échéance') and unite = 'Pourcentage' then 1
    	WHEN indicateur in ('Dont directement imputables','Dont directement rapprochées','Dont directement BAP',
    	'Dont en régularisation','Dont saisies en retard','Dont exception de rapprochement','Dont approbation après échéance','Pièces acheminées',
    	'Dont délai < 15 jours','Dont délai entre 15 et 30 jours','Dont délai entre 30 et 45 jours','Dont délai entre 45 et 60 jours','Dont délai > 60 jours') and unite = 'Montant' then 0
        WHEN indicateur = 'Total traitées' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Total traitées' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Total réglées' and unite = 'Nombre' then s1_nbr_paid
        WHEN indicateur = 'Total réglées' and unite = 'Montant' then s1_mnt_tt_paid
        WHEN indicateur = 'Dont retard' and unite = 'Nombre' then s1_nb_p_late
        WHEN indicateur = 'Dont retard' and unite = 'Montant' then s1_mnt_p_late
        WHEN indicateur = 'Dont retard' and unite = 'Pourcentage' then CASE WHEN s1_mnt_tt_paid <> 0 THEN s1_nb_p_late/s1_mnt_tt_paid ELSE 0 END
        WHEN indicateur = 'Acquisition' and unite = 'Nombre' then s1_nbr_acq
        WHEN indicateur = 'Acquisition' and unite = 'Montant' then s1_mnt_tt_acq
        WHEN indicateur = 'Dont manuelles' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'ONL' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont manuelles' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'ONL' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont EDI' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'EDI' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont EDI' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'EDI' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Dont Numérisation' and unite = 'Nombre' then CASE WHEN orig.s1_cde_orig = 'NUM' THEN S1_NBR_ACQ ELSE 0 END
        WHEN indicateur = 'Dont Numérisation' and unite = 'Montant' then CASE WHEN orig.s1_cde_orig = 'NUM' THEN S1_MNT_TT_ACQ ELSE 0 END
        WHEN indicateur = 'Pièces imputées' and unite = 'Nombre' then s1_nbr_acct
        WHEN indicateur = 'Pièces imputées' and unite = 'Montant' then s1_mnt_tt_acct
        WHEN indicateur = 'Dont directement imputables' and unite = 'Nombre' then s1_nbr_dir_imp
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Nombre' then s1_nbr_mtch
        WHEN indicateur = 'Pièces rapprochées' and unite = 'Montant' then s1_mnt_tt_mtch
        WHEN indicateur = 'Dont directement rapprochées' and unite = 'Nombre' then s1_nbr_dir_rap
        WHEN indicateur = 'Pièces approuvées' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Pièces approuvées' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Dont directement BAP' and unite = 'Nombre' then s1_nb_auto
        WHEN indicateur = 'Commandes' and unite = 'Nombre' then CASE WHEN S1_PO_FLG = '1' THEN s1_nbr_appr ELSE 0 END
        WHEN indicateur = 'Commandes' and unite = 'Montant' then CASE WHEN S1_PO_FLG = '1' THEN s1_mnt_tt_appr ELSE 0 END
        WHEN indicateur = 'Dont en régularisation' and unite = 'Nombre' then s1_nb_regul
        WHEN indicateur = 'Réceptions' and unite = 'Nombre' then s1_nbr_acq
        WHEN indicateur = 'Réceptions' and unite = 'Montant' then s1_mnt_tt_acq
        WHEN indicateur = 'Dont saisies en retard' and unite = 'Nombre' then s1_nb_rcpt_sup
        WHEN indicateur = 'Rapprochement' and unite = 'Nombre' then s1_nbr_mtch
        WHEN indicateur = 'Rapprochement' and unite = 'Montant' then s1_mnt_tt_mtch
        WHEN indicateur = 'Dont exception de rapprochement' and unite = 'Nombre' then s1_nbr_mtch-s1_nb_ss_except
        WHEN indicateur = 'Dont existence R500' and unite = 'Nombre' then CASE WHEN S1_R500_FLG = '1' THEN S1_NBR_MTCH ELSE 0 END
        WHEN indicateur = 'Dont existence R500' and unite = 'Montant' then CASE WHEN S1_R500_FLG = '1' THEN S1_MNT_TT_MTCH ELSE 0 END
        WHEN indicateur = 'Approbation' and unite = 'Nombre' then s1_nbr_appr
        WHEN indicateur = 'Approbation' and unite = 'Montant' then s1_mnt_tt_appr
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Nombre' then 0
        WHEN indicateur = 'Dont approbation après échéance' and unite = 'Pourcentage' then 0
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Nombre' then CASE WHEN mnt.s1_borne_inf < 300 THEN s1_nbr_appr ELSE 0 END
        WHEN indicateur = 'dont pièces < 300 euros' and unite = 'Montant' then CASE WHEN mnt.s1_borne_inf < 300 THEN s1_mnt_tt_appr ELSE 0 END
        WHEN indicateur = 'Pièces acheminées' and unite = 'Nombre' then s1_nbr_created
        WHEN indicateur = 'Dont délai < 15 jours' and unite = 'Nombre' then s1_nb_ach_15
        WHEN indicateur = 'Dont délai entre 15 et 30 jours' and unite = 'Nombre' then s1_nb_ach_30
        WHEN indicateur = 'Dont délai entre 30 et 45 jours' and unite = 'Nombre' then s1_nb_ach_45
        WHEN indicateur = 'Dont délai entre 45 et 60 jours' and unite = 'Nombre' then s1_nb_ach_60
        WHEN indicateur = 'Dont délai > 60 jours' and unite = 'Nombre' then s1_nb_ach_60
        WHEN indicateur = 'Pièces payées' and unite = 'Nombre' then s1_nbr_paid
        WHEN indicateur = 'Pièces payées' and unite = 'Montant' then s1_mnt_tt_paid
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Nombre' then 0
        WHEN indicateur = 'Dont pénalités de retard' and unite = 'Montant' then s1_penal_amt
        ELSE 0 
      END) as valeur

  5. #5
    Modérateur
    Avatar de Waldar
    Homme Profil pro
    Customer Success Manager @Vertica
    Inscrit en
    Septembre 2008
    Messages
    8 452
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Customer Success Manager @Vertica
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2008
    Messages : 8 452
    Points : 17 820
    Points
    17 820
    Par défaut
    Oui vous avez raison je suis bête, une seule des conditions est résolue à chaque fois.

    Je vous encourage à faire une table de matrice pour la résolution de ce genre de calcul, mais il faut d'abord vous faire un référentiel d'indicateur et d'unité.

  6. #6
    Membre émérite Avatar de pacmann
    Homme Profil pro
    Consulté Oracle
    Inscrit en
    Juin 2004
    Messages
    1 626
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Consulté Oracle
    Secteur : Distribution

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 626
    Points : 2 845
    Points
    2 845
    Par défaut
    Salut !

    Je suis un peu étonné que ça ralentisse tant que ça le traitement...
    Tu as testé en remplaçant le case par juste un sum(col), où col n'est pas dans un index ? (juste pour limiter les chances de modifier le plan d'exécution).

    Si c'est vraiment ton problème, comment sont réparties les valeurs ?
    => s'il y a vraiment des cas qui apparaissent plus souvent que d'autres, il faut les tester en premier, car le case s'arrête à priori au premier "hit".

    (c'est ma photo)
    Paku, Paku !
    Pour les jeunes incultes : non, je ne suis pas un pokémon...

    Le pacblog : http://pacmann.over-blog.com/

Discussions similaires

  1. Optimisation LEFT avec CASE WHEN
    Par Invité dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 26/09/2013, 20h16
  2. case/when avec plusieurs valeurs pour le then
    Par Neo41 dans le forum Langage SQL
    Réponses: 7
    Dernier message: 02/09/2005, 15h58
  3. Pb avec case when !
    Par Brice Yao dans le forum Langage SQL
    Réponses: 11
    Dernier message: 05/08/2005, 08h20
  4. Structure CASE WHEN en Interbase
    Par tchaman dans le forum InterBase
    Réponses: 8
    Dernier message: 13/12/2004, 16h18
  5. [SQL] performances Decode ou Case when ?
    Par Yorglaa dans le forum Oracle
    Réponses: 8
    Dernier message: 01/10/2004, 15h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo