case 
when (出勤天数 + round(( 行政 + 周末 + 法定 )/ 8.0,1) ) >=15 then 
case 
when 岗位 in ('AA工','SS班长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in ('10508')) 
then 0
when 岗位 in ('YY组长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in('10509','10510')) 
then 0
else 补贴 
end
else  0
end  

解决方案 »

  1.   

    case when (出勤天数 + round(( 行政 + 周末 + 法定 )/ 8.0,1) ) >=15 
    then
    case
    when 岗位 in ('AA工','SS班长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in ('10508'))
    then 0
    when 岗位 in ('YY组长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in('10509','10510'))
    then 0
    else 补贴
    end
    else  0 end 
    排一下格式
      

  2.   

    case  when (出勤天数 + round(( 行政 + 周末 + 法定 )/ 8.0,1) ) >=15 then 
      case  when 岗位 in ('AA工','SS班长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in ('10508')) 
              then 0 
             when 岗位 in ('YY组长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in('10509','10510')) 
             then 0 
            else 补贴  end 
          else  0 
    end 
    语法是没有问题的。
    不过  substring(部门编号,1,3) in('10509','10510')   这个能有结果吗。
    substring(部门编号,1,3) 得长度最多为3,和'10509' 为什么 等长度为5 得内容比较 ?
      

  3.   

    语法没错,但这两个逻辑不对吧?怎么也满足不了吧?
    substring(部门编号,1,3) in ('10508')
    substring(部门编号,1,3) in ('10509','10510')
      

  4.   

    他娘的,说什么then附近语法错误!没看出来什么错误?!!
      

  5.   

    没加括号 至少里层的case没加 应该是(case when (出勤天数 + round(( 行政 + 周末 + 法定 )/ 8.0,1) ) >=15 then
        (case when 岗位 in ('AA工','SS班长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in ('10508')) then 0
              when 岗位 in ('YY组长') and 部门编号 not in (select 部门编号 from 部门表 where substring(部门编号,1,3) in('10509','10510')) then 0
         else 补贴 end)
        else  0 end)