Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
INNER JOIN with MAX MIN
Message
De
07/09/2021 17:55:57
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01682244
Message ID:
01682268
Vues:
60
>Update:
>I had to fiddle somewhat, but I could imagine this would be working:
>
>WITH ranked_status AS (
> SELECT Orders.Id, Orders.KdNr, Orders.Status, ROW_NUMBER() OVER (PARTITION BY KdNr ORDER BY id DESC) AS row_number
> FROM Orders AS m
>)
>SELECT Auftrag.KdNr, Min_Id.Id, Max_Status.Status
>FROM Auftrag
>JOIN (SELECT MIN(Id) AS Id, KdNr FROM Orders GROUP BY KdNr) Min_Id ON Min_Id.KdNr = Auftrag.KdNr
>JOIN (SELECT Status, KdNr FROM ranked_status WHERE row_number = 1) Max_Status ON Max_Status.KdNr = Auftrag.KdNr

Thanks
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform