Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Show maximum of 3 columns
Message
De
17/09/2001 16:25:02
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00557471
Message ID:
00557495
Vues:
15
>>>For each record, I need to retrieve the maximum of 3 columns.
>>>
>>>Example:
>>>ID 1 has column C1= 2, C2=5, C3=1
>>>ID 2 has column C1=6, C2=3, C3=8
>>>
>>>I need maximum of C1,C2,C3:
>>>ID 1 gives 5
>>>ID 2 gives 8
>>>
>>>Can we do this using SELECT statement?
>>>Thank you all!
>>
>>
>>select field1, field2, max(c1, c2, c3) as mymax from table1
>>
>>
>>HTH,
>
>It wouldn't work because in this case Max is SQL Select not Foxpro function.
>The following shoud work (not tested)
>
>SELECT Id, ;
>    IIF( (c1 > c2) and (c1 > c3), c1,
>      IIF( (c2 > c1) and (c2 > c3), c2, c3)) as MaxVal ;
>  FROM mytable ;
>  INTO CURSOR mycursor
>
Oops, my bad... :(

Or create a function called myMax, accepting the 3 parameters, returning max(p1, p2, p3).
Steve Gibson
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform