Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get a Top n dataset grouped.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00680116
Message ID:
00681667
Vues:
24
>>>< snip >>
>>>>Hi
>>>>I'm afraid it will become too complcated and slow-running query but you caould try somethink like this:
>>>>
 SELECT t.LotNumber, t.Container, t.Lot_Pieces, t.Lot_Balance FROM MyTable t
>>>>     WHERE t.LotNumber IN (SELECT top 3 sq.LotNumber, sq.Container, sq.Lot_Balance
>>>>                          FROM MyTable sq
>>>>                          WHERE sq.Container = t.Container )
>>>>
>>>
>>>First, in VFP SELECT TOP n requires ORDER BY clause. Second, such subquery would generate an error.
>>
>>Sergey, I know ORDER BY requirements and this is just an idea.
>>Of course Martin should know how will he order the desired top 3 record (may be on LotNumber)
>>I do not have the data to test it.
>>Why do you think it will generate an error?
>
>Venelina,
>
>I tried many times to get subquery like that to work w/o any success.

Well, surely this is working:
create a procedure (my is called test)
Parameters currentContainer, currentLotNo 
SELECT top 3 sq.LotNumber, sq.Container, sq.Lot_Balanc ;
              FROM MyTable sq;
              WHERE sq.Container = currentContainer and sq.Lot_Balanc < 100 order by LotNumber;
              into cursor tempResults
Locate for LotNumber = currentLotNo
Result = Found()
USE in tempResults
Return Result
and use it in your WHERE clause
Set Procedure To c:\temp\test\test.prg
SELECT t.LotNumber, t.Container, t.Lot_Pieces, t.Lot_Balanc FROM c:\temp\test\test t;
     WHERE test(t.Container, t.LotNumber)
I just had tried it.
My field is named Lot_Balanc, because I tried it with free table.
Venelina Jordanova

Outsourcing IT Services Ltd.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform