遇到一业务,用到一个sql不会写了,抽象出来是这样:
字段1引用字段2
比方这样:selec 1 a ,case when a=1 then 'b1' else 'b2' end from dual;
就是说,要查两个字段,如果a=1的话,b就是b1,否则就是b2如何解决,求教!
字段1引用字段2
比方这样:selec 1 a ,case when a=1 then 'b1' else 'b2' end from dual;
就是说,要查两个字段,如果a=1的话,b就是b1,否则就是b2如何解决,求教!
直接
select 变量,case 变量=1 then b1 else b2 end from table
a=1的话是 b1
a=2的话是 b2
a=3的话是 b3
还能用这个函数吗?
select decode(a,1,'b1',2,'b2',3,'b3') from table;
case类似.
selec 1 a ,decode(a,1,'b1','b2') b from dual;
select 1 a,decode(a,1,'b1',2,'b2',3,'b3',....n,'bn') b from table;
select a1, case when a1=1 then b1 else b2 end b from table_name
select a1, case when a1=1 then 'b1' else 'b2' end b from table_name