Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
There HAS to be a better way
Message
De
31/01/2013 20:35:13
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
There HAS to be a better way
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01564910
Message ID:
01564910
Vues:
105
Please note: VFP 8

I have a cursor with a Uniq_Key, Version, and isProduction flag. The table is created with a
SELECT fields FROM table ORDER BY uniqKey, isProduction DESC, version DESC
and some sample data looks like
Uniq_Key   isProd   Version
K1              1            1  <----
K2              0            3  <----
K2              0            2
K2              0            1
K3              1            3 <----
K3              0            2
K3              0            1
K4              1            2 <----
K4              0            3
K4              0            1
Note K4 shows a newer version but the production flag has not been set.

What I need is a way to get the first version for each Uniq_Key
Uniq_Key      Version
K1                  1
K2                  3
K3                  3
K4                  2
Maybe I'm having a super-senior day but I can't come up with anything better than
SELECT uniq_key,version,RECNO() as recno FROM myCursor INTO CURSOR tmp1
SELECT uniq_key,min(recno) as recno FROM rlp1 GROUP BY uniq_key INTO CURSOR tmp2
SELECT tmp1.* from tmp1 JOIN tmp2 ON tmp1.uniq_key = tmp2.uniq_key AND tmp1.recno = tmp2.recno INTO CURSOR tmp3
I don't want to rely on RECNO() (although I think it's safe in a single table select).

It seems as if there has to be a better way of doing this.

All suggestions appreciated.........Rich
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform