Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Record from same table
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01240631
Message ID:
01240825
Views:
23
>
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform