Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2828 connectés 

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [SQL] Supprimer les lignes 'inutiles' dans mon résultat...

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[SQL] Supprimer les lignes 'inutiles' dans mon résultat...

n°701017
Arjuna
Aircraft Ident.: F-MBSD
Posté le 16-04-2004 à 13:37:00  profilanswer
 

Voilà, j'ai une petite question.
 
J'ai la requête ci-dessous (attention les mirette :)) :


select f.CODEFAM, f.CODESFA, f.CODESSF, f.LIBFAM, decode(p.fampro, f.codefam, decode(p.sfapro, f.codesfa, decode(p.ssfpro, f.codessf, p.codpro, ' '), ' '), ' ')  
from fml f, pro p
where p.codsoc = 0 and p.codpro in ('1A00473', '1A00032', '1A00065', '1A00178')
and f.codsoc = 0 and f.typtie = 'PRO' and f.codlan = 'FRA'
and ((f.codefam = p.fampro and f.niveau = 1) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.niveau = 2) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.codessf = p.ssfpro and f.niveau = 3))  
union
select f.CODEFAM, f.CODESFA, f.CODESSF, f.LIBFAM, decode(p.fampro, f.codefam, decode(p.sfapro, f.codesfa, decode(p.ssfpro, f.codessf, p.codpro, ' '), ' '), ' ')
from fam f, pro p
where p.codsoc = 0 and p.codpro in ('1A00473', '1A00032', '1A00065', '1A00178')
and f.codsoc = 0 and f.typtie = 'PRO' and not exists (select null  
                               from fml ff  
                 where ff.codsoc = 0 and ff.typtie = 'PRO' and ff.codlan = 'FRA' and ff.codefam = f.codefam and ff.codesfa = f.codesfa and ff.codessf = f.codessf)  
and ((f.codefam = p.fampro and f.niveau = 1) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.niveau = 2) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.codessf = p.ssfpro and f.niveau = 3))
order by 1, 2, 3, 5  


 
Elle me retourne ça :


CODEFAM CODESFA CODESSF LIBFAM                  CODPRO
------- ------- ------- ----------------------- -------
1APRCH                  PAPIER ECG ET EEG  
1APRCH  CHART           PAPIER ECG ET EEG  
1APRCH  CHART   ZFOLD   PLIAGE                  1A00032
1APRPR                  SUPPORT D'IMPRESSION  
1APRPR  PRINT           SUPPORT D'IMPRESSION  
1APRPR  PRINT           SUPPORT D'IMPRESSION    1A00178
1APRPR  PRINT   THERMA  PAPIER THERMIQUE        1A00065
1APRPR  PRINT   THERMA  PAPIER THERMIQUE        1A00473


 
J'aimerais faire une passe supplémentaire (dans un having ?) pour supprimer les lignes où CODPRO est vide alors qu'il existe des lignes dans le résultat où le triplet "CODEFAM, CODESFA, CODSSF" est identique, et CODPRO n'est pas vide.
 
Vous avez une idée de comment faire ?
 
En somme, je veux :


CODEFAM CODESFA CODESSF LIBFAM                  CODPRO
------- ------- ------- ----------------------- -------
1APRCH                  PAPIER ECG ET EEG  
1APRCH  CHART           PAPIER ECG ET EEG  
1APRCH  CHART   ZFOLD   PLIAGE                  1A00032
1APRPR                  SUPPORT D'IMPRESSION  
1APRPR  PRINT           SUPPORT D'IMPRESSION    1A00178
1APRPR  PRINT   THERMA  PAPIER THERMIQUE        1A00065
1APRPR  PRINT   THERMA  PAPIER THERMIQUE        1A00473


Message édité par Arjuna le 16-04-2004 à 13:38:51
mood
Publicité
Posté le 16-04-2004 à 13:37:00  profilanswer
 

n°701054
Arjuna
Aircraft Ident.: F-MBSD
Posté le 16-04-2004 à 14:05:49  profilanswer
 

J'ai trouvé !  [:bool_de_gom]
 


select CODEFAM, CODESFA, CODESSF, LIBFAM, CODPRO
from  
(
select f.CODEFAM, f.CODESFA, f.CODESSF, f.LIBFAM, decode(p.fampro, f.codefam, decode(p.sfapro, f.codesfa, decode(p.ssfpro, f.codessf, p.codpro, ' '), ' '), ' ') CODPRO  
from fml f, pro p
where p.codsoc = 0 and p.codpro in ('1A00473', '1A00032', '1A00065', '1A00178')
and f.codsoc = 0 and f.typtie = 'PRO' and f.codlan = 'FRA'
and ((f.codefam = p.fampro and f.niveau = 1) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.niveau = 2) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.codessf = p.ssfpro and f.niveau = 3))  
union
select f.CODEFAM, f.CODESFA, f.CODESSF, f.LIBFAM, decode(p.fampro, f.codefam, decode(p.sfapro, f.codesfa, decode(p.ssfpro, f.codessf, p.codpro, ' '), ' '), ' ') CODPRO
from fam f, pro p
where p.codsoc = 0 and p.codpro in ('1A00473', '1A00032', '1A00065', '1A00178')
and f.codsoc = 0 and f.typtie = 'PRO' and not exists (select null  
                               from fml ff  
                 where ff.codsoc = 0 and ff.typtie = 'PRO' and ff.codlan = 'FRA' and ff.codefam = f.codefam and ff.codesfa = f.codesfa and ff.codessf = f.codessf)  
and ((f.codefam = p.fampro and f.niveau = 1) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.niveau = 2) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.codessf = p.ssfpro and f.niveau = 3))
) p1
where not exists (select null from (select f.CODEFAM, f.CODESFA, f.CODESSF, f.LIBFAM, decode(p.fampro, f.codefam, decode(p.sfapro, f.codesfa, decode(p.ssfpro, f.codessf, p.codpro, ' '), ' '), ' ') CODPRO  
from fml f, pro p
where p.codsoc = 0 and p.codpro in ('1A00473', '1A00032', '1A00065', '1A00178')
and f.codsoc = 0 and f.typtie = 'PRO' and f.codlan = 'FRA'
and ((f.codefam = p.fampro and f.niveau = 1) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.niveau = 2) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.codessf = p.ssfpro and f.niveau = 3))  
union
select f.CODEFAM, f.CODESFA, f.CODESSF, f.LIBFAM, decode(p.fampro, f.codefam, decode(p.sfapro, f.codesfa, decode(p.ssfpro, f.codessf, p.codpro, ' '), ' '), ' ') CODPRO
from fam f, pro p
where p.codsoc = 0 and p.codpro in ('1A00473', '1A00032', '1A00065', '1A00178')
and f.codsoc = 0 and f.typtie = 'PRO' and not exists (select null  
                               from fml ff  
                 where ff.codsoc = 0 and ff.typtie = 'PRO' and ff.codlan = 'FRA' and ff.codefam = f.codefam and ff.codesfa = f.codesfa and ff.codessf = f.codessf)  
and ((f.codefam = p.fampro and f.niveau = 1) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.niveau = 2) or (f.codefam = p.fampro and f.codesfa = p.sfapro and f.codessf = p.ssfpro and f.niveau = 3))
) p2 where p2.CODEFAM = p1.CODEFAM and p2.CODESFA = p1.CODESFA and p2.CODESSF = p1.CODESSF and p2.CODPRO != ' ' and p1.CODPRO = ' ')
order by 1, 2, 3, 5


Message édité par Arjuna le 16-04-2004 à 14:10:43
n°701304
Beegee
Posté le 16-04-2004 à 17:34:52  profilanswer
 

illisible :D

n°701311
Arjuna
Aircraft Ident.: F-MBSD
Posté le 16-04-2004 à 17:41:26  profilanswer
 


Dans TOAD c'est bien indenté, mais le forum sait pas faire...

n°701322
Arjuna
Aircraft Ident.: F-MBSD
Posté le 16-04-2004 à 17:50:02  profilanswer
 

Tiens, regarde :)
 
http://perso.wanadoo.fr/magicbuzz/req.png


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [SQL] Supprimer les lignes 'inutiles' dans mon résultat...

 

Sujets relatifs
[vba excel] affichage de resultat d'excel sous word ?Est-ce normal d'avoir 200 lignes de code pour en afficher 4 ?
[SQL] Erreur incompréhensible (insert into)problème SQL sur une plateforme W2003Server et SQL 2000
[SQL] Requete update qui ne s'effectue pasProblème de requête SQL
[Windev] interaction avec SQL Serverenregistrer le resultat d'une fonction dans une table de base de donné
[SQL] order by Sum(...)Résultat toujours = 0
Plus de sujets relatifs à : [SQL] Supprimer les lignes 'inutiles' dans mon résultat...


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)