Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select SQL and ORDER BY...defective?
Message
De
25/02/2000 00:09:53
 
Information générale
Forum:
Visual FoxPro
Catégorie:
FoxPro 2.x
Divers
Thread ID:
00337312
Message ID:
00337341
Vues:
17
*** posted again for better formatting, doggone it! ***

Real,

>Because I need to regroup the oldest accounts due by clients.
>For easiest reading I'll use ANSI date (yyyy.mm.dd) in this exemple.
>
>   DATE    CLT_CODE
>1996.01.01 FFF
>1998.01.01 FFF
>1999.01.01 FFF
>2000.02.24 FFF
>
>1997.01.01 BBB
>2000.02.22 BBB
>
>1999.12.31 AA
>2000.10.01 AA
>
>You see the oldest account is the first oldest reference for each client.

Let's see if I understand this correctly. You want the first client in the result to be the one with the oldest account, with all of his records in date order, then on to the next oldest account, with all of its records in date order....

Try this. It's two SQL statements with a REPLACE command, but it will do the job.
SELECT 000000 AS clt_order, ;
MIN(date) AS firstdate, ;
clt_code AS ccode ;
FROM invoice ;
INTO TABLE inv_temp1 ;
GROUP BY 3 ;
ORDER BY 2
* at this point you have a table with oldest invoice 
* for each customer, sorted by date (the table name 
* really should be a unique name that will not conflict 
* with any other user)
* make the order usable in the next SQL SELECT
SELECT inv_temp1
REPLACE ALL clt_order WITH RECNO()
* now do the final select
SELECT date, clt_code ;
FROM invoice ;
INNER JOIN inv_temp1 ON clt_code = ccode ;
ORDER BY temp1.clt_order, date
Not very elegant, but it does the job. Others may have a simpler way, but I can't think of it.
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform