One possibility, using ROW_NUMBER
:
WITH cte AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY state_date) rn
FROM yourTable
)
SELECT customer_id, customer_type, customer_state, state_date,
MAX(CASE WHEN rn = 1 THEN customer_type END) OVER
(PARTITION BY customer_id) first_type
FROM cte;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…