mysql> SELECT CASE 1 WHEN 1 THEN 'one'

    ->     WHEN 2 THEN 'two' ELSE 'more' END;

        -> 'one'

mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;

        -> 'true'

mysql> SELECT CASE BINARY 'B'

    ->     WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;

        -> NULL

一个CASE表达式的默认返回值类型是任何返回值的相容集合类型,但具体情况视其所在语境而定。如果用在字符串语境中,则返回结果味字符串。如果用在数字语境中,则返回结果为十进制值、实值或整数值。

 

语句:

select  sum(case teacherLevel.levName when'一线' then course.classTimes else 0 end  ) as frontline

 

from  consult_student_course as course  

 

      left join consult_student_payment as payment on course.payId = payment.payId 

 

      left join school_campus as campus on campus.camId in (payment.secondPayCamId,payment.firstPayCamId)   

 

      left join sys_teacher_level as teacherLevel on teacherLevel.tlevId = course.tlevId