Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL help
Message
 
 
À
18/07/2002 15:25:49
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00680170
Message ID:
00680263
Vues:
19
Bill,

Here's one way to do the whole thing with 3 SQLs, no scan loop necessary
* find all valid commissions per guest

select guests.*, commissions.effdate, commissions.commission, ( guests.date - commissions.effdate ) as delta ;
   from commissions ;
   inner join guests ;
      on commissions.emp = guests.emp ;
   into cursor x1 ;
   having delta > 0

* find the earliest valid

select x1.guest, x1.emp, min(delta) as delta ;
   from x1 ;
   into cursor x2 ;
   group by guest, emp

* pull the earliest rows out of x1 to get the final result

select x1.guest, x1.date, x1.emp, x1.effdate, x1.commission ;
   from x1 ;
   inner join x2 ;
      on x1.guest = x2.guest and x1.emp = x2.emp and x1.delta = x2.delta ;
   into cursor finalanswer ;
   order by 1,2
>I want to match each guest with the Commission due the Emp for that date.
>
>desired cursor:
>Guest    Date    Emp    Effective    Commission
>-----------------------------------------------
>1        4/4/2   1      1/1/1        100
>2        4/4/2   2      1/1/1        100
>3        5/4/2   1      5/1/2        125
>4        5/4/2   2      1/1/1        100
>5        6/4/2   1      6/1/2        150
>6        6/4/2   2      6/1/2        110
>
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform