I have a table that follow order status and logging some events in warehouses and delivery notes.
My table looks like this, with a lot of Load_ID’s and order events:
enter image description here
I want an output with one row per load_ID and some of the timestamps in separate columns.
What I want as output is something like this, one row per load_ID and some of the timestamps i each column:
enter image description here
What i tried:
SELECT
distinct Load_ID,
MAX(case when Order_Event in ("Loaded") and transport_Type = "A" then (Timestamp) end) Loading_TS_WH1
MAX(case when Order_Event in ("Loaded") and transport_Type = "B" then (Timestamp) end) Loading_TS_WH2
MAX(case when Order_Event in ("Delivered") then (Timestamp) end) Delivered_TS
from
Table_1
group by
Load_ID
But what I get is a result like this, with the max (highest values) timestamps in both columns where i use a “loaded” timestamp, even if i use the transport_type as a condition:
enter image description here
How to get the timestamp where the order_event is ‘Loaded’ and transport_type is ‘A’ ?