Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select the highest value from each group?
Message
 
À
30/05/2005 16:51:42
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01018590
Message ID:
01018593
Vues:
9
This message has been marked as a message which has helped to the initial question of the thread.
What about:
create cursor tblValues ( ;
  cKey       c( 32 ), ;
  cValue     c( 16 ), ;
  nPriority  i        ;
)

insert into tblValues values ('apple', 'red',     8)
insert into tblValues values ('apple', 'yellow',  2)
insert into tblValues values ('apple', 'brown',   0)

insert into tblValues values ('corn',  'green',   4)
insert into tblValues values ('corn',  'yellow',  9)
insert into tblValues values ('corn',  'brown',   2)

insert into tblValues values ('eggs',  'pink',    6)
insert into tblValues values ('eggs',  'purple',  7)
insert into tblValues values ('eggs',  'white',   8)


select	tblValues.cKey, ;
	tblValues.cValue, ;
	tblValues.nPriority ;
   from  tblValues ;
   join  ( ;
            select    T.cKey, ;
                      Max(T.nPriority) as nMaxPriority ;
               from   tblValues as T;
               group  by 1 ;
         ) MaxPriorityTemp ;
      on   tblValues.cKey = MaxPriorityTemp.cKey and ;
      		tblValues.nPriority = MaxPriorityTemp.nMaxPriority ;
   into cursor c_test
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform