Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting the Max
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01132678
Message ID:
01132683
Vues:
14
This message has been marked as the solution to the initial question of the thread.
>I feel like I've done this before but for the life of me I can't remember how I did it:
>
>Using just SQL Select how can I get the items with the Max count.
>
>Source table
>
>ColumnCode1  ColumnCode2  ColumnCode3   CodeCount
>Code1          Code2         code3         3
>Code1          Code2         Code4         2
>
>
>What I'm trying to get to is for each identical ColumnCode1, ColumnCode2 I want to see only the ColumnCode3 with the most CodeCount.
>
>Something like this:
>
>ColumnCode1  ColumnCode2  ColumnCode3
>Code1          Code2         code3
>
>
>Any ideas?
>
>Richard
SELECT MyTable.ColumnCode1,MyTable.ColumnCode2, MyTable.ColumnCode3, MyTable.CodeCount;
FROM MyTable;
INNER JOIN (SELECT ColumnCode1,ColumnCode2, MAX(CodeCount) AS CodeCount FROM MyTable GROUP BY ColumnCode1,ColumnCode2) Tbl1;
      ON MyTable.ColumnCode1 = Tbl1.ColumnCode1 AND;
         MyTable.ColumnCode2 = Tbl1.ColumnCode2 AND;
         MyTable.CodeCount   = Tbl1.CodeCount;
INTO CURSOR crsTest
BROW NORMAL
(not tested)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform