ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: SQL - Dédoublonner un curseur selon des critères hiérarchisé   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

jeu. 19 juillet 2012, 08h32

FoxInCloud (Th. Nivelet)
France France

atoutfox.public.association

Re: SQL - Dédoublonner un curseur selon des critères hiérarchisé

On peut même faire toute l'opération (extraction et dédoublonnage) en une seule requête

  SELECT;
    BREN_.cTable;
  ,  BREN_.ID;
  ,  BREN_.cTitre;
  ,  BREN_.dItem;
  ,  BREN_.nOccs;
  ,  BREN_.Bbib_Soci;
  , BREN_.ID_BBIB;
  ,  BREN_.Bbib_budg;
  ,  BREN_.Bbib_type;
  ,  BREN_.France;
  FROM (;
    SELECT;
        'BREN' AS cTable;
      , BREN.ID AS ID;
      ,  Cast(Trim(BREN.BREN_titr, ' ', CR, LF) AS C(200)) AS cTitre;
      , Ctod(BREN.BREN_date+"/20"+BREN.BREN_anne) AS dItem;
      , wIndex.nOccs AS nOccs;
      , Upper(BBIB.Bbib_Soci) AS Bbib_Soci;
      , BBIB.ID AS ID_BBIB;
      , BBIB.Bbib_budg;
      , Evl(BBIB.Bbib_type, '9') AS Bbib_type;
      , Empty(BBIB.Bbib_pays) AS France;
      FROM Data\BREN;
        JOIN Data\wIndex ON BREN.ID = wIndex.ID_rec;
        JOIN Data\BBIB ON BREN.BBIB_code = BBIB.BBIB_code;
      WHERE .T.;
        AND wIndex.ID_thesau = m.lID_wThesau;
        AND wIndex.Nom_log = 'BREN';
        AND wIndex.nOccs > 1;
      ORDER BY 3,4;
    ) BREN_ JOIN (;
    SELECT;
      BREN_.cTitre;
    ,  BREN_.Bbib_budg;
    ,  BREN_.Bbib_type;
    ,  BREN_.France;
    ,  BREN_.Bbib_Soci;
    ,  Max(BREN_.dItem) AS dItem;
    FROM BREN_ JOIN (;
      SELECT;
        BREN_.cTitre;
      ,  BREN_.Bbib_budg;
      ,  BREN_.Bbib_type;
      ,  BREN_.France;
      ,  Min(BREN_.Bbib_Soci) AS Bbib_Soci;
      FROM BREN_ JOIN (;
        SELECT;
          BREN_.cTitre;
        ,  BREN_.Bbib_budg;
        ,  BREN_.Bbib_type;
        ,  Max(BREN_.France) AS France;
        FROM BREN_ JOIN (;
          SELECT;
            BREN_.cTitre;
          ,  BREN_.Bbib_budg;
          ,  Min(BREN_.Bbib_type) AS Bbib_type;
          FROM BREN_ JOIN (;
            SELECT;
              BREN_.cTitre;
            ,  Max(BREN_.Bbib_budg) AS Bbib_budg;
            FROM BREN_;
            GROUP BY 1;
          ) BREN1 ON .T.;
              AND BREN_.cTitre = BREN1.cTitre;
              AND BREN_.Bbib_budg = BREN1.Bbib_budg;
            GROUP BY 1,2;
        ) BREN2 ON .T.;
            AND BREN_.cTitre = BREN2.cTitre;
            AND BREN_.Bbib_budg = BREN2.Bbib_budg;
            AND BREN_.Bbib_type = BREN2.Bbib_type;
          GROUP BY 1,2,3;
      ) BREN3 ON .T.;
          AND BREN_.cTitre = BREN3.cTitre;
          AND BREN_.Bbib_budg = BREN3.Bbib_budg;
          AND BREN_.Bbib_type = BREN3.Bbib_type;
          AND BREN_.France = BREN3.France;
        GROUP BY 1,2,3,4;
    ) BREN4 ON .T.;
        AND BREN_.cTitre = BREN4.cTitre;
        AND BREN_.Bbib_budg = BREN4.Bbib_budg;
        AND BREN_.Bbib_type = BREN4.Bbib_type;
        AND BREN_.France = BREN4.France;
        AND BREN_.Bbib_Soci = BREN4.Bbib_Soci;
      GROUP BY 1,2,3,4,5;
  ) BREN5 ON .T.;
      AND BREN_.cTitre = BREN5.cTitre;
      AND BREN_.Bbib_budg = BREN5.Bbib_budg;
      AND BREN_.Bbib_type = BREN5.Bbib_type;
      AND BREN_.France = BREN5.France;
      AND BREN_.Bbib_Soci = BREN5.Bbib_Soci;
      AND BREN_.dItem = BREN5.dItem;
  ORDER BY 3,4;
  INTO CURSOR BREN_


Permalink : http://www.atoutfox.org/nntp.asp?ID=0000009412
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3