Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sql Syntax to make this group by ?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00755254
Message ID:
00755455
Vues:
16
This message has been marked as the solution to the initial question of the thread.
Rock,

Assuming that bigger UniqueId means later note
SELECT * FROM mytable mt1
  WHERE NOT EXISTS (
     SELECT * FROM mytable mt2
          WHERE mt2.ClientId = mt1.ClientId 
              And ( mt2.date > mt1.date OR mt2.UniqueId > mt2.UniqueId) )
If UniqueId cannot be used for that than you've to define how to determine in terms of data which note with the same date is latest.

>Hi Sergey thank's a lot for you answer but if i have 2 note with the same date
>i would like to get only one per client in my result
>
>Have a Idea ?
>Rock
>
>
>>There are a few ways to do that.
-- #1
>>SELECT * FROM mytable mt1
>>  WHERE NOT EXISTS (
>>     SELECT * FROM mytable mt2
>>          WHERE mt2.ClientId = mt1.ClientId And mt2.date > mt1.date)
>>-- #2
>>SELECT * FROM mytable mt1
>>  WHERE date IN (
>>     SELECT MAX(date) FROM mytable mt2
>>          WHERE mt2.ClientId = mt1.ClientId)
>>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform