Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Group by with an order field
Message
 
À
15/09/2010 12:51:51
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01481294
Message ID:
01481297
Vues:
36
This message has been marked as the solution to the initial question of the thread.
>The following SQL allows me to group by RO_No and collect a date time field with it:
>
>
>SELECT Event.RO_No,max(Event.DateTime) as LastDateTime FROM Event GROUP BY Event.RO_No
>
>
>However, I need to adjust that so the group by will only applies to the first 10 records of an order to Event.DateTime. Basically, if I wouldn't have a group by, the SQL would be this:
>
>
>SELECT TOP 10 Event.RO_No,Event.DateTime FROM Event ORDER by Event.DateTime
>
>
>But, on that result, I need to only get the unique occurence of Event.RO_No.

If I understood your question correctly you can do ORDER BY MAX(Event.DateTime) from the first select (and adding the top 10 to it)
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform