Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
INNER JOIN with MAX MIN
Message
From
07/09/2021 17:55:57
 
 
To
03/09/2021 01:10:20
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01682244
Message ID:
01682268
Views:
59
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform