Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select the highest value from each group?
Message
 
To
30/05/2005 16:51:42
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01018590
Message ID:
01018593
Views:
8
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform