高手求一SQL语句,高手请进!!!!!!!

kingyond 2004-03-29 06:05:10
表一,客户表customer
customer_id number(10) //客户ID,索引,无重复
customer_link_id number(10) //客户首选联系人
表二,客户联系人列表 customer_link
customer_link_id number(10)//客户ID,索引,无重复
customer_name varchar2(100)//客户选联系人
customer_id number(10)
假定表一数据如下,
customer_id customer_link_id
1001 2001
1002 0 //没有首选联系人
1003 2002
表二数据如下
customer_link_id customer_link_name customer_id
2001 csdn 1001
2002 www.taneipc.net 1001
2003 iloveu 1002
求一条sql语句返回以下结果:
customer_id customer_link_name
1001 csnd
1002 empty//为空
1003 www.taneipc.net

问题就出在首选联系人为空的时候
我开始是用以下select语句的:
select customer.customer_id,customer_link_name from
customer left jion customer_link on
customer.customer_link_id=customer_link.customer_link_id
结果可以返回选择
但是返回 customer_link_name 首选联系人为空处错误(变为非空值)。
每二次改为:
select customer.customer_id,customer_link_name from
customer left jion (select customer_link.customer_link_id,customer_link,customer_link_name
from customer_link inner join customer on customer.customer_link_id=customer_link.customer_link_id) on
customer.customer_link_id=customer_link_id
结果可以返回,但是出错地方依旧。
请高手指点?????????????????
...全文
11 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kingyond 2004-03-29
请问高手位,那里有SQL教程的电子版,请与我联系,谢谢!
QQ:900483
Msn:youngou98@hotmail.com
email:young@taneipc.net
Young@ptsenglish.com
回复
kingyond 2004-03-29
谢谢三位!结贴啦!
回复
beckhambobo 2004-03-29
select a.customer_id,nvl(b.customer_link_name,'empty') from
customer a,customer_link b where a.customer_link_id=b.customer_link_id(+);
回复
xinpingf 2004-03-29
高手求sql语句
回复
skystar99047 2004-03-29
select a.customer_id,nvl(b.customer_link_name,'无') from
customer a,customer_link b where a.customer_link_id=b.customer_link_id(+);
回复
xiaodongisme 2004-03-29
SELECT a.customer_id,b.customer_link_name FROM customer a,customer_link b
WHERE a.customer_link_id = b.customer_link_id(+)
ORDER BY a.customer_id
回复
kingyond 2004-03-29
表二写错了,以下为更正后的内容
表二,客户联系人列表 customer_link
customer_link_id number(10)//客户联系人ID,索引,无重复
customer_link_name varchar2(100)//客户联系人名字
customer_id number(10) //表一中的ID

回复
相关推荐
发帖
基础和管理
创建于2007-09-28

1.7w+

社区成员

Oracle 基础和管理
申请成为版主
帖子事件
创建了帖子
2004-03-29 06:05
社区公告
暂无公告