Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select records
Message
From
09/09/2004 09:56:12
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
09/09/2004 08:40:06
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00940543
Message ID:
00940612
Views:
24
>hi,
>thank you for reply,
>
>i don't say 3 tables ,i have one table have all records(area,days)
>
>choice 800 randomly from avery day for avery area,insert to new table
>
>thanks

I think you have already asked similar questions in other threads, right?

Let me try this.

If the table is very large, the following solution may be too slow. But for a reasonable amount of records, it might be fast enough.

The idea is to add a field with random information, to help in the random selection of data.

Assume your table is called "MyTable", and the fields are called "area" and "days". Area can have values 1, 2 or 3; you want exactly 800 records.
use MyTable
copy structure to TempResult
use TempResult in 0
select *, rand() * 0.000000 as random;
  from MyTable;
  into cursor Temp;
  order by area, random
go top
for i = 1 to 3
  select Temp
  locate rest for area = i
  copy next 800 to temp2 while area = i
  select TempResult
  append from temp2
next
Depending on the situation, other methods might be faster. For example, you might write a loop that creates a random record number in the range from 1 to reccount(), and copies one record at a time. If it is important that you don't get the same record twice, you might have to check for duplicates every time you copy a record.

HTH,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform