Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compute many operations
Message
 
 
À
09/09/2004 17:50:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00939290
Message ID:
00940865
Vues:
23
Ok, what is not working in that code? I changed RecNum to rn in the delete statement since rn is the name of the field (in Sergey's Select-SQL). I do not see, where do you print your information. What are AreaCode and Team fileds? Are they integer or character?

>hi,
>
>i use vfp8,
>
>
>SET TALK OFF
>SET ECHO OFF
Moved next two lines here, because we need to open table2 just once, not inside the scan loop
 SELECT 0 && Always use 0 instead of explicit number, 0 will open the next available area
>    USE  table2 alias table2 && I would use better names for my tables even for temporary
>* Step 1 - calculate percentages
>* Each team record count per each area
>select areacode, team, count(*) as TeamCount from table1 ;
>group by areacode, team into cursor curTeamCount
>
>* Total number of records per area from every team
>select areacode, count(*) as AreaCount from table1 ;
>group by areacode into cursor curAreaCount
>
>>#define TotalFetchNumber 150 && We need to have 150 records per each area
>#define Multiplier 4
>* Percentage of each team record count per area
>select curTeamCount.areacode, team, TeamCount, ;
>         AreaCount, ;
>        TeamCount/AreaCount*100 as Percentage, ;
>        floor((TeamCount/AreaCount) *  TotalFetchNumber * Multiplier) as NumToFetch ;
>         from curTeamCount inner join curAreaCount on ;
>        curTeamCount.areaCode = curAreaCount.areaCode into cursor curPercentage ;
>        order by 1, 2 && AreaCode, Team
>
>>* Close cursors, which are no longer needed
>use in curAreaCount
>use in curTeamCount
>
>>local lnNumberToExtract, lnAreaCode, lnTeam && Assuming AreaCode and Team are integer PKs
>
>select curPercentage
>scan
>     
>   
>   lnAreaCode = curPercentage.AreaCode
>lnTeam = curPercentage.Team
>
>lnNumberToExtract = curPercentage.NumToFetch
>if m.lnNumberToExtract<curPercentage.TeamCount
>   ** Now use code from Sergey Berezniker / Al Doman
>    SELECT TOP lnNumberToExtract *, RECNO() AS rn,  ;
>   ROUND(RAND()*10000000000,0) AS ord ;
>    FROM table1 ;
>    WHERE AreaCode = m.lnAreaCode and Team = m.lnTeam ;
>    ORDER BY ord ;
>    INTO CURSOR crsRand
>else && we exceed original number of records, just select all records for that team
>   select *, recno() as rn from table1 WHERE AreaCode = m.lnAreaCode and Team = m.lnTeam into cursor crsRand NOFILTER
>endif
>
>>
>   select table2 && Note, that we need to open table2 only once, not in the scan 
>     append from dbf("crsRand")
>    delete from table1 where recno() in (select rn from crsRand)>
>>    use in crsRand && we do not need our crsRand anymore
>  endscan
>REPORT FORM rpt1 preview
>use in curPercentage
>
>
>
>thanks
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