在联表 join 时 使用 case when 按不同的条件关联不同的行

 

SELECT
OrderID,
Quantity,
CASE
WHEN Quantity > 30 THEN 'The quantity is greater than 30'
WHEN Quantity = 30 THEN 'The quantity is 30'
ELSE 'The quantity is under 30'
END AS QuantityStatus
FROM OrderDetails;
 
 
select
1
from table_a a
left jion
table_b b 
on a.f0=b.f0
and (
case when a.fb1="scene" then a.fb2=b.fb2
else 1
end 
)

 

posted @ 2026-08-13 14:42  papering  阅读(2)  评论(0)    收藏  举报