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

Requêtes MySQL Discussion :

2 SELECT Pour en faire qu'un ?


Sujet :

Requêtes MySQL

  1. #1
    Membre actif
    Inscrit en
    Avril 2009
    Messages
    308
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 308
    Points : 231
    Points
    231
    Par défaut 2 SELECT Pour en faire qu'un ?
    Bonjour !

    Je me trouve face à une requête qui me donne bien des soucis.

    J'ai 2 requête Select la 1ère me sert à trouvé les différents type de chambre.
    La seconde des prix et un sous type.

    J'essaye en vain de mettre chaque prix dans sa typologie de chambre avec un select imbriqué, ce que certain appel de la cosmétique, mais j'ai pas le choix, le site met un temps fous à faire le dispatche des données dans les bonnes colonnes (30 à 40 secondes après reception des donnée )

    J'ai fais un essaie et j'ai quelque-chose comme ça :

    ||PERIODE || SOUS TYPE ||TYPE DE CHAMBRE || PRIX||
    01/10au11/10 ||DELUX|| DOUBLE
    12/10au01/11 ||STANDART|| DOUBLE
    01/10au11/10 ||DELUX|| TRIPLE
    12/10au01/11 ||STANDART|| TRIPLE
    01/10au11/10 ||DELUX|| QUADRUPLE
    12/10au01/11 ||STANDART|| QUADRUPLE
    01/10au11/10 || DELUX|| SINGLE
    12/10au01/11 ||STANDART|| SINGLE


    Et j'essaye d'avoir un résultat de ce type :

    ||PÉRIODE ||SOUS TYPE||DOUBLE ||TRIPLE||QUADRUPLE||SINGLE||
    01/10au11/10 || DELUX|| prix
    12/10au01/11 || DELUX|| prix

    01/10au11/10 || STANDART|| prix
    12/10au01/11 || STANDART|| prix


    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
    select 
    LIB_TYPE_SERVICE as 'TYPE_DE_CHAMBRE',
    from 
    SERVICE_PRIX
    inner join
    TYPE_SERVICE on SERVICE_PRIX.IDTYPE_SERVICE = TYPE_SERVICE.IDTYPE_SERVICE
    inner join
    FOURNISS_PRIX on FOURNISS_PRIX.IDFOURNISS_PRIX = SERVICE_PRIX.IDFOURNISS_PRIX
    where 
    CDFOURNISS_FOURNISS_PRIX ="209714"
    and 
    CDCONTRAT = "F1" 
    and CDSERVICE = "H"
    and TYPE_TYPE_SERVICE = 1
    group by  LIB_TYPE_SERVICE
    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
    select service_prix.PA_SERVICE_PRIX,
    service_prix.PV1_SERVICE_PRIX,
    FOURNISS_PRIX.CDFOURNISS_FOURNISS_PRIX,
    CDCONTRAT_FOURNISS_PRIX,
    CDEXCURSIO,
    DATE_FOURNISS_PRIX as "PERIODE",
    CDCLIENT,IDTYPE_SERVICE,
    EV_ABREV_FOURNISS_PRIX,
    SA_ABREV_FOURNISS_PRIX
    from service_prix
    inner join fourniss_prix on fourniss_prix.IDFOURNISS_PRIX = service_prix.IDFOURNISS_PRIX
    where 
    FOURNISS_PRIX.CDFOURNISS_FOURNISS_PRIX = "209714"
    and CDCONTRAT_FOURNISS_PRIX = "F1"
    order by DATE_FOURNISS_PRIX

    Le TYPE de chambre n'est pas déterminé à l'avance j'avais pensé à faire un CASE mais c'est pas possible...

    Merci pour votre aide !

  2. #2
    Membre actif
    Inscrit en
    Avril 2009
    Messages
    308
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 308
    Points : 231
    Points
    231
    Par défaut
    Bonjour !

    J'ai donc finalement réussi à imbriquer les 2 select comme il suit, la "présentation" diffère un peu de ce que je voulait au départ mais c'est pas plus mal.

    Maintenant je me pose une question.
    Dans cette requête je conditionne en "DUR" avec des if le cdexcursio ("DELUX","STRANDAR",JUNIOR")

    Mon seul problème maintenant c'est qu'il y à n type de cdexcursio existant et que c'est des "données" qui changent fréquemment.

    La je vois pas trop comment en premier faire un select de tout les cdexcursio et imbriquer cette requête....

    Sa devient compliqué pour moi la

    Edit: N'étant pas sur que ce soit réalisable, je vais faire ça depuis le code en faisant un select distinct de tout les cdexcursio, puis pour chaque valeur de retour exécuter cette seconde requête en remplaçant les valeur dans le if.

    Mais si quelqu'un à une idée Merci !

    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
    select 
    DATE_FOURNISS_PRIX,
     
    max(QRY.PDOUBLE_STD) AS DOUBLE_STANDARD,
    max(QRY.PSINGLE_STD) AS SINGLE_STANDARD,
    max(QRY.PTRIPLE_STD) AS TRIPLE_STANDARD,
    max(QRY.PQUAD_STD) AS QUAD_STANDARD,
     
    max(QRY.PDOUBLE_DELUX) AS DOUBLE_DELUX,
    max(QRY.PSINGLE_DELUX) AS SINGLE_DELUX,
    max(QRY.PTRIPLE_DELUX) AS TRIPLE_DELUX,
    max(QRY.PQUAD_DELUX) AS QUAD_DELUX,
     
    max(QRY.PDOUBLE_JUNIO) AS DOUBLE_JUNIOR,
    max(QRY.PSINGLE_JUNIO) AS SINGLE_JUNIOR,  
    max(QRY.PTRIPLE_JUNIO) AS TRIPLE_JUNIOR,
    max(QRY.PQUAD_JUNIO) AS QUAD_JUNIOR
     
    from  ( select DATE_FOURNISS_PRIX,
     
    if(IDTYPE_SERVICE = 20090 and fourniss_prix.cdexcursio is null,min(service_prix.PV1_SERVICE_PRIX) ,0) as PDOUBLE_STD,
    if(IDTYPE_SERVICE = 20475  and fourniss_prix.cdexcursio is null,min(service_prix.PV1_SERVICE_PRIX) ,0)  as PSINGLE_STD,
    if(IDTYPE_SERVICE = 20091 and fourniss_prix.cdexcursio is null,min(service_prix.PV1_SERVICE_PRIX) ,0)  as PTRIPLE_STD,
    if(IDTYPE_SERVICE = 20093 and fourniss_prix.cdexcursio is null,min(service_prix.PV1_SERVICE_PRIX) ,0)  as PQUAD_STD,
     
    if(IDTYPE_SERVICE = 20090 and fourniss_prix.cdexcursio ='DELUX',min(service_prix.PV1_SERVICE_PRIX) ,0) as PDOUBLE_DELUX,
    if(IDTYPE_SERVICE = 20475  and fourniss_prix.cdexcursio ='DELUX',min(service_prix.PV1_SERVICE_PRIX) ,0)  as PSINGLE_DELUX,
    if(IDTYPE_SERVICE = 20091 and fourniss_prix.cdexcursio ='DELUX',min(service_prix.PV1_SERVICE_PRIX) ,0)  as PTRIPLE_DELUX,
    if(IDTYPE_SERVICE = 20093 and fourniss_prix.cdexcursio ='DELUX',min(service_prix.PV1_SERVICE_PRIX) ,0)  as PQUAD_DELUX,
     
    if(IDTYPE_SERVICE = 20090 and fourniss_prix.cdexcursio ='JUNIO',min(service_prix.PV1_SERVICE_PRIX) ,0) as PDOUBLE_JUNIO,
    if(IDTYPE_SERVICE = 20475  and fourniss_prix.cdexcursio ='JUNIO',min(service_prix.PV1_SERVICE_PRIX) ,0)  as PSINGLE_JUNIO,
    if(IDTYPE_SERVICE = 20091 and fourniss_prix.cdexcursio ='JUNIO',min(service_prix.PV1_SERVICE_PRIX) ,0)  as PTRIPLE_JUNIO,
    if(IDTYPE_SERVICE = 20093 and fourniss_prix.cdexcursio ='JUNIO',min(service_prix.PV1_SERVICE_PRIX) ,0)  as PQUAD_JUNIO
     
    from fourniss_prix,service_prix
     
    where fourniss_prix.IDFOURNISS_PRIX = service_prix.IDFOURNISS_PRIX 
    and CDFOURNISS_FOURNISS_PRIX ='xx'
    and CDCONTRAT_FOURNISS_PRIX ='xx'
    and CDCLIENT is null  
    and DATE_FOURNISS_PRIX between 20091101 and 20101031 
    group by DATE_FOURNISS_PRIX,IDTYPE_SERVICE,CDEXCURSIO
    order by DATE_FOURNISS_PRIX
    )
    as QRY 
    group by 
    DATE_FOURNISS_PRIX 
    order by DATE_FOURNISS_PRIX

Discussions similaires

  1. Requete select pour faire un Update
    Par tralala2 dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 03/10/2009, 16h11
  2. Utiliser UPDATE + SELECT pour faire un cache FIFO
    Par WeeJay dans le forum Langage SQL
    Réponses: 5
    Dernier message: 19/05/2008, 12h10
  3. Réponses: 2
    Dernier message: 02/02/2008, 22h38
  4. utilisation de select() pour faire un Tchat
    Par innosang dans le forum Réseau
    Réponses: 30
    Dernier message: 09/11/2005, 16h15
  5. Requete select pour récupérer les no match entre 2 tables
    Par Celina dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 16/12/2003, 11h59

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