现有A,B两张表,当A表name字段不为空取A表name,如果A表name为空取B表name,取别名为hangye,如果两者都为空显示99未分类,请大佬们帮我看一下
IFNULL(A.name ,IFNULL(B.name ,"99未分类" ))AS hangye,不需要case when,case when 一般都是同一个字段
case when一般这样用法
(case ecr.status when 0 then '待处理' when 1 then '同意' when 2 then '拒绝' when 3 then '撤销' else '' end ) statusName,这样的同一个字段进行判断
select
(
case when A.name is null and B.name is null then
'99未分类'
case when A.name is null then
B.name
else
A.name end
) as hangye from A,B;
A与B怎么关联,你自己修改