我没看明白意思 是否是 select biao1.id, level=(case when(biao1.level=1) then '低' when(biao1.level=2) then '中' when(biao1.level=3) then '高' end) from biao1 join biao2 on biao1.id=biao2.id
select case level when 1 then '低' when 2 then '中' when 3 then '高' end from biao1, biao2 where biao2.id =biao1.id
select b.id, case a.level when 1 then '低' when 2 then '中' when 3 then '高' else '未知' end from biao1 a right join biao2 b on a.id=b.id这个不行吗?按你的意思来看这条语句应该是满足你的要求的。
(select b.id, (case a.level when 1 then '低' when 2 then '中' when 3 then '高' else '未知' end ) as level from biao1 a right join biao2 b on a.id=b.id) union all ( select a.id,'未知' as level from biao1 a where a.id not in (select b.id from biao2 b) )
是否是
select biao1.id, level=(case when(biao1.level=1) then '低'
when(biao1.level=2) then '中'
when(biao1.level=3) then '高' end)
from biao1 join biao2 on biao1.id=biao2.id
else后面写的是id在biao1和biao2都存在,但level值不在case 枚举范围之内的。我的意思是把biao2里的所有记录都显示出来,对于某个id在biao1没有的则给它赋上一个值例如'未知',有办法吗?谢谢!
case a.level when 1 then '低' when 2 then '中' when 3 then '高' else '未知' end
from biao1 a right join biao2 b on a.id=b.id这个不行吗?按你的意思来看这条语句应该是满足你的要求的。
(case a.level when 1 then '低' when 2 then '中' when 3 then '高' else '未知' end )
as level
from biao1 a right join biao2 b on a.id=b.id)
union all
(
select a.id,'未知' as level from biao1 a where a.id not in (select b.id from biao2 b)
)