有一张表A,属性id,name,extend,其中extend字段为空,一张表C,属性id ,extend,c.extend不为空,
其中表C.id是表A.id子集。现在需要使用SQL实现这样的功能
如果A.id = C.id 那么 a.extend = c.extend 否则 a.extend = 0 ?
其中表C.id是表A.id子集。现在需要使用SQL实现这样的功能
如果A.id = C.id 那么 a.extend = c.extend 否则 a.extend = 0 ?
解决方案 »
- 恳请高人帮忙看下程序
- sql 语句 when exit
- 我这样的分区表改如何建索引?
- willnum>(select avg(willnum),couname,couno from course问题
- 求救 ORACLE 编程删除记录太慢 不释放空间
- Oracle ERP 中如何设置多时区
- [紧急求助!]Oracle 10g 启动问题?
- 一个小问题,orcal安装问题!
- 请教“面试试题”中的一道sql的查询语句的写法
- 我的创建表空间的脚本创建不成功???在线等!
- UNION和UNION ALL的区别
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 oracle的分页,这个sql语句怎么改成oracle
from a,c
where a.id=c.id and a.extend = c.extend
union all
select a.id,a.name,a.extend
from a,c
where a.extend = 0 and not exists(select 1
from c where a.id=c.id)
不好意思,我没有说明白,a.extend = c.extend 否则 a.extend = 0 是复制的意思,就是把c.extend赋值给a.extend.
from a,c
where a.id=c.id
select nvl(max(extend),0) from c where id=a.id
and rownum<2)
请问这个能实现a.id 在c.id没有的情况下a.extend要用0填写??好像不行吧
set extent =
(select nvl(extent,0) from c where id = a.id)
update a set extend=(select nvl(extend,0) from c where a.id=c.id)
SQL> select * from c;ID NA EXTEND
-- -- ----------
1 a 11
2 b 22
3 c 33SQL> select * from a;ID NA EXTEND
-- -- ----------
1 a
2 b
3 c
4 d
5 eSQL> update a set extend=(
2 select nvl(max(extend),0) from c where id=a.id
3 and rownum<2)
4 /5 rows updated.SQL> select * from a;ID NA EXTEND
-- -- ----------
1 a 11
2 b 22
3 c 33
4 d 0
5 e 0