Quote: 引用:Quote: 引用:譬如表A,有字段flag,和字段a,b,c,d,e,f当flag=‘1’,取出字段a,b,c其他情况,取出字段d,e,fwith t as (select 1 flag, 1 a, 2 b, 3 c, 4 d, 5 e, 6 f from dual union all select 2 flag, 1 a, 2 b, 3 c, 4 d, 5 e, 6 f from dual)select decode(flag, 1, a, b), decode(flag, 1, c, d), decode(flag, 1, e, f) from t;这么搞太复杂了,还是老实写两条查询吧。。。
Quote: 引用:譬如表A,有字段flag,和字段a,b,c,d,e,f当flag=‘1’,取出字段a,b,c其他情况,取出字段d,e,fwith t as (select 1 flag, 1 a, 2 b, 3 c, 4 d, 5 e, 6 f from dual union all select 2 flag, 1 a, 2 b, 3 c, 4 d, 5 e, 6 f from dual)select decode(flag, 1, a, b), decode(flag, 1, c, d), decode(flag, 1, e, f) from t;
譬如表A,有字段flag,和字段a,b,c,d,e,f当flag=‘1’,取出字段a,b,c其他情况,取出字段d,e,f
with t as (select 1 flag, 1 a, 2 b, 3 c, 4 d, 5 e, 6 f from dual union all select 2 flag, 1 a, 2 b, 3 c, 4 d, 5 e, 6 f from dual)select decode(flag, 1, a, b), decode(flag, 1, c, d), decode(flag, 1, e, f) from t;