Skip to content
Advertisement

Merging Rows and put values in different columns

I have the following table:

and want to get to this result:

An ID value in the first table occurs max 4 times:

Booked + 1 = was either marked booked the first time in database OR was either marked booked the last time in database

Booked + 0 = was either marked not-booked the first time in database OR was either marked not-booked the last time in database

In python I am able to manage this problem, but I face performance issues. Maybe someone knows how I can handle this in SQL Server Management Studio to achieve a speedup.

Advertisement

Answer

You can use conditional aggregation:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement