Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Group By
Message
 
 
À
21/04/2009 09:42:25
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01395684
Message ID:
01395749
Vues:
77
You're welcome.

>Thanks Sergey. Your first example worked well in my situation.
>
>>There're many ways to get such result. Pick one that is most efficient for your data
>>
>>* 1
>>SELECT * FROM mytable mt1 
>>  WHERE StartDate = (SELECT MAX(StartDate) FROM mytable mt2 where mt2.fk = mt1.fk)
>>
>>* 2
>>SELECT * FROM mytable mt1 
>>  JOIN (SELECT fk, MAX(StartDate) AS MaxStartDate FROM mytable GROUP BY fk) dt1
>>    ON dt1.fk = mt1.fk AND dt1.MaxStartDate = mt1.StartDate 
>>
>>* 3
>>SELECT * FROM mytable mt1 
>>  WHERE NOT EXISTS (SELECT 1 FROM mytable mt2 where mt2.fk = mt1.fk AND mt2.StartDate > mt1.StartDate)
>>
>>
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform