表
SELECT o.receipt, COALESCE(r1.amount, r2.amount, r3.amount) as amount
FROM ORDERS as o
LEFT JOIN RECEIPT1 as R1 ON o.receipt = r1.receipt and o.order_type = 'c'
LEFT JOIN RECEIPT2 as R2 ON o.receipt = r2.receipt and o.order_type = 'x'
LEFT JOIN RECEIPT3 as R3 ON o.receipt = r3.receipt and o.order_type = '??'
查询
Type | Name | Condition
Fruit | Apple | Fair
Fruit | Apple | Fair
Veg | null | Good
Veg | Tomato | Great
尝试让案例显示重复项和空白的值。我想要生成为“空白”的第二个WHEN语句在运行语句后不会生成值。这似乎只在运行SELECT子查询后才会发生。