高手求一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
结果可以返回,但是出错地方依旧。
请高手指点?????????????????
...全文
43 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧