sql语句按条件取值



   根据类型返回字段名   如果是0 返回  用户名 如果是 1 返回机构名

select t.rcv_type, decode(t.rcv_type, 0, (select tt.name
                                           from tb_user tt
                                         where t.* ** **
                                          ), 1, (select ttt.dept_name
                                                                  from tb_dept ttt
                                                                where t.* ** **
                                                                
                                                                 ))
  from TB_AFFICHE_RECEIVER t


where后面关联条件

猜你喜欢

转载自apple578994358gg.iteye.com/blog/2064231