You should get a syntax error, because the select
columns are inconsistent with the group by
. Use aggregation:
SELECT orderId,
MAX(CASE WHEN status = 'opened' THEN date END) AS openedDate,
MAX(CASE WHEN status = 'closed' THEN date END) AS closedDate
FROM orders
GROUP BY orderId;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…