在select語句里面可以使用case來對某個colmun的值進行分別處理,比如
select case color
when 1 then 'red'
when 2 then 'green'
when 3 then 'blue'
else 'black'
end as 'colorName',
foodName from foods
如果使用了left join的時候,某個column的null值需要給一個default value的話,也可以如下:
select foodName, case
when foodPrice is null then 0
else foodPrice
end as price,
foodCost from foods left join foodPrices on foods.foodId = foodPrices.foodId
或者
when nullif(foodPrice, null) is null then 0