表A:
id
表B id_b
表C id_icselect decode(a.id_type,
1,(select b.b_desc from B b where b.id_b=a.id_a),
2,(select c.c_desc from C c where c.id_c=a.id_a)
) discription,
a.*
from A a
这条语句还可以怎么写?不用decode,兄弟们多多发贴,多多益善
id
表B id_b
表C id_icselect decode(a.id_type,
1,(select b.b_desc from B b where b.id_b=a.id_a),
2,(select c.c_desc from C c where c.id_c=a.id_a)
) discription,
a.*
from A a
这条语句还可以怎么写?不用decode,兄弟们多多发贴,多多益善
解决方案 »
- 查看Oracle的连接数,以及每增加一个连接数,所消耗的CPU。
- Oracle日期的格式
- ORA-00955: 名称已由现有对象使用
- 请教: Oracle数据库中怎么实现Access数据库的ID(自动编号)的功能?
- 问一个问题 sql
- 请教一个sql语句
- 求助关于使用resin如何远程连接oracle数据库的问题
- 关于Oracle触发器的一个无知的问题
- 初学Oracle,想了解一些Oracle的基本概念(象表空间,方案,例程等),不知道那里有
- 为何select * 就没有用到索引?
- SQL中如何调用返回类型为record的函数
- 我想在这个存储过程的游标中加条件,根据输入的值进行判断,请大家帮我修改以下,总是报错
from a
left join b on b.id_b=a.id_a
left join c on c.id_c=a.id_a
不过,最好不要楼主的这种子查询,1楼的左连接更好
你可以用union连接
select b.b_desc description,a.*
from A a,B b
where a.id_a=b.id_b and a.id_type=1
union
select c.c_desc description,a.*
from A a,C c
where a.id_a=c.id_c and a.id_type=2
select nvl((select b.b_desc
from B b
where b.id_b = a.id_a
and a.id_type = 1),
(select c.c_desc
from C c
where c.id_c = a.id_a
and a.id_type = 2))) discription, a.*
from A a