Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Record from same table
Message
 
 
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 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01240631
Message ID:
01240825
Vues:
24
>
>ID         Name       Year          No
>1          Khubaib     2005          5
>1          Khubaib     2006          6
>1          Khubaib     2007          7
>
>I would like
>
>id       name      (year)no    (year)no
>
>1        khubaib       5         6
Khubaib,

You may try the following procedural code:
create cursor curFinal (ID I, Name C(20), No1 I, No2 I)
select * from myTable into cursor curTemp nofilter order by ID, Year 
index on str(ID) + str(Year,4)
set exact off
select distinct ID from curTemp into cursor curIDs order by 1

select curIDs
scan
   select curTemp
   =seek(str(curIDs.ID)) && I assume it would be the first record in the index sequence
   insert into curFinal values (curTemp.ID, curTemp.Name, curTemp.No)
   if not eof('curTemp')
      skip
      if not eof('curTemp') and curTemp.ID = curIDs.ID
          replace No2 with curTemp.No in curFinal
      endif 
   endif
endscan
This would result in the two lowest years data inserted for each ID.

From the top of my head and not tested. Not sure if this is a good algorithm and I can not quickly figure a pure SQL solution.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform