Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query help needed
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01296873
Message ID:
01296880
Vues:
11
Using Borislav's idea:
SELECT YourTable.* from YourTable inner JOIN 
(SELECT YourTable.Id,
        YourTable.DateSaved
        max(YourTable.TimeSaved) as MaxTime 
FROM YourTable
INNER JOIN (SELECT Id, MAX(DateSaved) AS DateSaved
                   FROM YourTable
            GROUP BY Id) Tbl1
      ON YourTable.Id    = Tbl1.Id AND
         YourTable.DateSaved = Tbl1.DateSaved) group by 1,2) sql ;
on YourTable.ID = sql.ID and YourTable.DateSaved = sql.DateSaved and YourTable.TimeSaved = sql.MaxTime
not tested and there could be better ideas, of course.




>Consider the table:
>
>Sn   Bal  DateSaved  TimeSaved
>1    200  2/5/2008   10:00
>1    175  2/5/2008   11:00
>1    123  2/5/2008   13:00
>1    111  2/6/2008   08:00
>1    101  2/6/2008   18:00
>2    500  2/8/2008   10:00
>2    475  2/8/2008   11:00
>
>
>I am trying write a query that will give me the following result set
>
>Sn   Bal  DateSaved  TimeSaved
>1    101  2/6/2008   18:00
>2    475  2/8/2008   11:00
>
>
>1 record per Sn where the DateSaved and the TimeSaved (together) is the newest datetime.
>
>Thanks,
>Einar
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform