select a.*,case a.a_user_identity when 0 then (select t.teacherNameChs from teacherinfo t where teacherId =a.a_user_id) else (select s.studentNameChs from studentinfo s where s.studentId =a.a_user_id)
end as username
from advice a
简单 CASE 函数:
CASE input_expressionWHEN when_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
END
CASE 搜索函数:
CASEWHEN Boolean_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
END
比如:
第一种用法:
SELECT name,CASE WHEN birthday < '1981' THEN 'old'
WHEN birthday > '1988' THEN 'yong'
ELSE 'ok' END YORN
FROM lee
第二种用法:
SELECT NAME, CASE nameWHEN 'sam' THEN 'yong'
WHEN 'lee' THEN 'handsome'
ELSE 'good' END as oldname
FROM lee
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)