例如
tabA
id name
1 tom
2 jack
3 lily
tabB
name num
tom 5
jack 3
需求结果
id name num
1 tom 5
2 jack 3
3 lily 0
mysql写法:
select ta.*,ifnull(tb.num,0) from tabA ta left join tabB tb on ta.name = tb.name;
oracle写法:
select ta.*,nvl(tb.num,0) from tabA ta left join tabB tb on ta.name = tb.name;
mysql写法:
select ta.*,isnull(tb.num,0) from tabA ta left join tabB tb on ta.name = tb.name;