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

Langage SQL Discussion :

Exemple sélection horizontale


Sujet :

Langage SQL

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Février 2008
    Messages : 39
    Points : 35
    Points
    35
    Par défaut Exemple sélection horizontale
    bonjour

    j'ai un tableau comme suit :
     Num | date réception | date manipulation | date délivrance | 
      1  |  01/01/2013    |    03/01/ 2013    |    10/01/2013   |   
    2  |  05/01/2013    |    07/01/ 2013    |    17/01/2013   |
    je veux sélectionner la date maximum entre ces dates horizontalement..
    donc mon tableau sera comme ça :
           Num   |  date réception   |  date manipulation        | date délivrance  |     Max       
    1    |  01/01/2013       |    03/01/ 2013            |    10/01/2013    |  10/01/2013 
           2    |  05/01/2013       |    07/01/ 2013            |    17/01/2013    |  17/01/2013
    la date la plus grande entre "date réception" et "date manipulation " et "date délivrance" et son Num 1 pour la ligne 1

    merci d'avance

  2. #2
    Membre chevronné
    Inscrit en
    Août 2009
    Messages
    1 073
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 1 073
    Points : 1 806
    Points
    1 806
    Par défaut
    Sur Oracle : GREATER
    Sur un autre SGBDR : utiliser des CASE :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    SELECT CASE WHEN (dtReception >= dtManipulation AND dtReception >= dtDelivrance) THEN dtReception
                       WHEN  (dtManipulation >= dtReception AND dtManipulation >= dtDelivrance) THEN dtManipulation 
                       ELSE dtDelivrance
                       END
    Ce qui se fait facilement à 3 dates, mais commence à devenir pénible ensuite !

  3. #3
    Membre expérimenté
    Avatar de islamov2000
    Homme Profil pro
    Ingénieur d'études & developpement en informatique
    Inscrit en
    Septembre 2007
    Messages
    814
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Ingénieur d'études & developpement en informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2007
    Messages : 814
    Points : 1 717
    Points
    1 717
    Billets dans le blog
    6
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    with test as
    (
     
    select 1 Num ,to_date('01/01/2013') date_réception, to_date('03/01/ 2013') date_manipulation, to_date('10/01/2013') date_délivrance from dual union
    select 2 ,to_date('05/01/2013'),to_date('07/01/2013'),to_date('17/01/2013 ')  from dual
    ),
    total as
    (
    select Num,date_réception les_dates from test union
    select Num,date_manipulation from test union
    select Num,date_délivrance from test)
     
    select  A.Num,A.date_réception, A.date_manipulation, A.date_délivrance  ,  max(B.les_dates) from test A join total B on A.num=B.num
    group by  A.Num,date_réception, date_manipulation, date_délivrance


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
       	NUM	DATE_RÉCEPTION	DATE_MANIPULATION	DATE_DÉLIVRANCE	MAX(B.LES_DATES)
    1	1	01/01/2013	03/01/2013	10/01/2013	10/01/2013
    2	2	05/01/2013	07/01/2013	17/01/2013	17/01/2013

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Février 2008
    Messages : 39
    Points : 35
    Points
    35
    Par défaut
    Tout d'abord je te remercie pour ton aide;
    j'utilise SQL server et j'utilise le code suivant mais ne fonction pas
    Mon table et ses champs sont :
    Table_2(dtReception ,dtManipulation,dtDelivrance )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    use test1
    SELECT CASE WHEN (dbo.Table_2.dtReception >=dbo.Table_2.dtManipulation AND dbo.Table_2.dtReception >= dbo.Table_2.dtDelivrance) 
    THEN  dbo.Table_2.dtReception
    WHEN  (dbo.Table_2.dtManipulation >=dbo.Table_2.dtReception AND dbo.Table_2.dtManipulation >= dbo.Table_2.dtDelivrance)
    THEN   dbo.Table_2.dtManipulation 
     ELSE   dbo.Table_2.dtDelivrance
    END
    et le message d'erreur est :
    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
     
    Msg 4104, Level 16, State 1, Line 4
    The multi-part identifier "dbo.Table_2.dtReception" could not be bound.
    Msg 4104, Level 16, State 1, Line 4
    The multi-part identifier "dbo.Table_2.dtManipulation" could not be bound.
    Msg 4104, Level 16, State 1, Line 4
    The multi-part identifier "dbo.Table_2.dtReception" could not be bound.
    Msg 4104, Level 16, State 1, Line 4
    The multi-part identifier "dbo.Table_2.dtDelivrance" could not be bound.
    Msg 4104, Level 16, State 1, Line 6
    The multi-part identifier "dbo.Table_2.dtManipulation" could not be bound.
    Msg 4104, Level 16, State 1, Line 6
    The multi-part identifier "dbo.Table_2.dtReception" could not be bound.
    Msg 4104, Level 16, State 1, Line 6
    The multi-part identifier "dbo.Table_2.dtManipulation" could not be bound.
    Msg 4104, Level 16, State 1, Line 6
    The multi-part identifier "dbo.Table_2.dtDelivrance" could not be bound.
    Msg 4104, Level 16, State 1, Line 5
    The multi-part identifier "dbo.Table_2.dtReception" could not be bound.
    Msg 4104, Level 16, State 1, Line 7
    The multi-part identifier "dbo.Table_2.dtManipulation" could not be bound.
    Msg 4104, Level 16, State 1, Line 8
    The multi-part identifier "dbo.Table_2.dtDelivrance" could not be bound.
    Fichiers attachés Fichiers attachés

  5. #5
    Modérateur

    Profil pro
    dba
    Inscrit en
    Janvier 2010
    Messages
    5 643
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : dba

    Informations forums :
    Inscription : Janvier 2010
    Messages : 5 643
    Points : 13 092
    Points
    13 092
    Par défaut
    Bonjour,

    Il manque le FROM dans votre requête !

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Février 2008
    Messages : 39
    Points : 35
    Points
    35
    Par défaut
    Bonjour,
    après ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    use test1
     
    SELECT CASE WHEN (dbo.Table_2.dtReception >= dbo.Table_2.dtManipulation AND dbo.Table_2.dtReception >= dbo.Table_2.dtDelivrance) 
    			THEN  dbo.Table_2.dtReception
    			WHEN  (dbo.Table_2.dtManipulation >=dbo.Table_2.dtReception AND dbo.Table_2.dtManipulation >= dbo.Table_2.dtDelivrance)
    			THEN   dbo.Table_2.dtManipulation 
                ELSE   dbo.Table_2.dtDelivrance
    END
    from dbo.Table_2
    ça marche bien
    merci a tous

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

Discussions similaires

  1. Exemple de sélection via formulaire
    Par wiwi dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 03/10/2008, 19h26
  2. Checrche Exemple d'application C++ Builder - MySQL
    Par pcatric dans le forum C++Builder
    Réponses: 12
    Dernier message: 11/11/2002, 23h51
  3. [VB6] Lancer un service, par exemple Sql Server
    Par fea dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 16/10/2002, 14h07
  4. recherche exemple simple pour corba en c++
    Par Pinggui dans le forum CORBA
    Réponses: 4
    Dernier message: 06/05/2002, 11h29

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