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 :

left outer et motif en ligne [10g]


Sujet :

SQL Oracle

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif
    Inscrit en
    Avril 2005
    Messages
    238
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 238
    Par défaut left outer et motif en ligne
    Bonjour,

    dans la requête ci-dessous, j'ai le problème suivant :

    Je voudrais que l'affichage se fasse en ligne pour le résultat.

    J'obtiens 2 lignes lorsqu'il y un motif du type GD et SPO.
    Je voudrais une seule ligne pour l'affichage : matri, date, code, nom, motif du type GD, motif du type SPO

    Est ce faisable ?
    Merci pour vos réponses.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    SELECT t1.matri, t1.date,t1.code, t2.nom, t3.motif From t1
    left outer join  t2 on t1.matri = t2.matri
    left outer join  t3 on t1.matri = t3.matri and t1.date = t3.date and t1.motif = t3.motif
    where t3.motif like 'GD%' or t3.motif like 'SPO%'

  2. #2
    Modérateur
    Avatar de Waldar
    Homme Profil pro
    Sr. Specialist Solutions Architect @Databricks
    Inscrit en
    Septembre 2008
    Messages
    8 454
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Sr. Specialist Solutions Architect @Databricks
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2008
    Messages : 8 454
    Par défaut
    Voici une solution :
    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
        select t1.matri
             , t1.date
             , t1.code
             , t2.nom
             , t3a.motif
             , t3b.motif
          from t1 
     left join t2      on t2.matri     = t1.matri
     left join t3 t3a  on t3a.matri    = t1.matri 
                      and t3a.date     = t1.date
                      and t3a.motif    = t1.motif
                      and t3a.motif like 'GD%'
     left join t3 t3b  on t3b.matri    = t1.matri 
                      and t3b.date     = t1.date
                      and t3b.motif    = t1.motif
                      and t3b.motif like 'SPO%';
    Et en voici une autre :
    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
        select t1.matri
             , t1.date
             , t1.code
             , t2.nom
             , max(case when t3.motif like 'GD%'  then t3.motif end) as motif_GD
             , max(case when t3.motif like 'SPO%' then t3.motif end) as motif_SPO
          from t1
     left join t2 on t2.matri     = t1.matri
     left join t3 on t3.matri     = t1.matri 
                 and t3.date      = t1.date
                 and t3.motif     = t1.motif
                 and (t3.motif like 'GD%'
                  or  t3.motif like 'SPO%')
      group by t1.matri
             , t1.date
             , t1.code
             , t2.nom;

  3. #3
    Membre très actif
    Inscrit en
    Avril 2005
    Messages
    238
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 238
    Par défaut
    bonjour,

    Merci pour vos réponses, mais lorsque que j'essaye de filtrer sur une date et un type de population précise (012019), le résultat de la requête est vide.
    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
    select s6pacti.matri
             , s6pacti.dat
             , s6pacti.codequal
             , hopempl.nompre
             , max(case when hophabs.motif like 'GD%'  then hophabs.motif end) as motif_GD
             , max(case when hophabs.motif like 'SPO%' then hophabs.motif end) as motif_SPO
          from s6pacti
     left join hopempl on hopempl.matri     = s6pacti.matri 
     left join hophabs on hophabs.matri     = s6pacti.matri 
                 and hophabs.dat     = s6pacti.dat
                 and hophabs.motif     = s6pacti.motif
                 and (hophabs.motif like 'GD%'
                  or  hophabs.motif like 'SPOR%')
    Where hophabs.dat = '23/09/2016' and hopempl.horsect = '012019'
      group by s6pacti.matri
             , s6pacti.dat
             , s6pacti.codequal
             , hopempl.nompre;

  4. #4
    Membre très actif
    Inscrit en
    Avril 2005
    Messages
    238
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 238
    Par défaut
    Désolé j'arrive à filtrer sur la population 012019 et la date mais les colonnes MOTIF_GD et MOTIF_SPO sont toutes à null alors que j'ai des données.
    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
    select s6pacti.matri
             , s6pacti.dat
             , s6pacti.codequal
             , hopempl.nompre
             , max(case when hophabs.motif like 'GD%'  then hophabs.motif end) as motif_GD
             , max(case when hophabs.motif like 'SPOR%' then hophabs.motif end) as motif_SPO
          from s6pacti
     left join hopempl on hopempl.matri     = s6pacti.matri 
     left join hophabs on hophabs.matri     = s6pacti.matri 
                 and hophabs.dat     = s6pacti.dat
                 and hophabs.motif     = s6pacti.motif
                 and (hophabs.motif like 'GD%'
                  or  hophabs.motif like 'SPOR%')
    where hopempl.horsect = '012019' and s6pacti.dat = '23/09/2016'
      group by s6pacti.matri
             , s6pacti.dat
             , s6pacti.codequal
             , hopempl.nompre;

  5. #5
    Membre très actif
    Inscrit en
    Avril 2005
    Messages
    238
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 238
    Par défaut
    Je crois que j'ai trouvé en retirant la liaison hophabs.motif = s6pacti.motif
    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
    select s6pacti.matri
             , s6pacti.dat
             ,S6pacti.motif
             , s6pacti.codequal
             , hopempl.nompre
             , max(case when hophabs.motif like 'GD%'  then hophabs.motif end) as motif_GD
             , max(case when hophabs.motif like 'SPOR%' then hophabs.motif end) as motif_SPO
             ,max(case when hophabs.motif like 'MANIN%' then hophabs.motif end) as motif_MAN
          from s6pacti
     left join hopempl on hopempl.matri     = s6pacti.matri 
     left join hophabs on hophabs.matri     = s6pacti.matri 
                 and hophabs.dat     = s6pacti.dat
                 --and hophabs.motif     = s6pacti.motif
                 and (hophabs.motif like 'GD%'
                  or  hophabs.motif like 'SPOR%'
                  or  hophabs.motif like 'MANIN%')
    where hopempl.horsect = '012019' and s6pacti.dat = '23/09/2016'
      group by s6pacti.matri
             , s6pacti.dat
             ,s6pacti.motif
             , s6pacti.codequal
             , hopempl.nompre;

  6. #6
    Membre très actif
    Inscrit en
    Avril 2005
    Messages
    238
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 238
    Par défaut
    Un dernière question ou puis je placer un order by dat ?
    Merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 02/04/2009, 10h24
  2. Problème avec left outer join
    Par jgfa9 dans le forum Requêtes
    Réponses: 1
    Dernier message: 22/08/2005, 22h07
  3. Nombre d'occurence d'un motif par ligne
    Par anne-so dans le forum Langage
    Réponses: 8
    Dernier message: 22/08/2005, 20h36
  4. Problème de performance avec LEFT OUTER JOIN
    Par jgfa9 dans le forum Requêtes
    Réponses: 6
    Dernier message: 17/07/2005, 14h17
  5. concatenation de chaine dans un left outer join
    Par the_edge dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 11/11/2004, 17h08

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