由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - how to make this query
相关主题
有关oracle form的新手问题SQL Query Question
老印给我的一个Challenge怎么reference temp table的column
其实我发现了CODE的写得好不好关于学习数据库我也说几句
Re: Recordset - I stuck! Help!correlated subquery
求教(SQL/Access): Join两个query tables 出错北京等高手,请帮忙tone一下这个query,周五才被DBA嘲笑过 :-(
请教一个SQL query该怎么写最近写了不少SQL script,请大牛评价下属于什么水平
包子请教query请教一个sql query
NOT= , NOT IN 有啥区别请问那种很复杂的sql语句,有什么套路吗?
相关话题的讨论汇总
话题: query话题: update话题: end话题: loop话题: make
进入Database版参与讨论
1 (共1页)
r***e
发帖数: 31
1
I have two relations A(a1,a2), B(b1,b2). I want to update the value of b2 to
a2 if a1 and b1 has the same value. How to write a query?
s******n
发帖数: 45
2
update B
set B.b2=A.a2
from A,B
where A.a1=B.b1

【在 r***e 的大作中提到】
: I have two relations A(a1,a2), B(b1,b2). I want to update the value of b2 to
: a2 if a1 and b1 has the same value. How to write a query?

r***e
发帖数: 31
3
It's not correct, I tried in ORACLE, it does not support update sth from
tables.
Does anyone know the answer?

to

【在 s******n 的大作中提到】
: update B
: set B.b2=A.a2
: from A,B
: where A.a1=B.b1

s******n
发帖数: 45
4
Hehe, it works on sql server.

【在 r***e 的大作中提到】
: It's not correct, I tried in ORACLE, it does not support update sth from
: tables.
: Does anyone know the answer?
:
: to

s******n
发帖数: 45
5
Try this with Oracle:
update B
set B.b2= (select A.a2 from A where A.a1=B.b1)
在 swingfan (狮子座小马的爸爸) 的大作中提到: 】
r***e
发帖数: 31
6
Acturally, I tried this before, it only works when you have unique a2 values.

【在 s******n 的大作中提到】
: Try this with Oracle:
: update B
: set B.b2= (select A.a2 from A where A.a1=B.b1)
: 在 swingfan (狮子座小马的爸爸) 的大作中提到: 】

s******n
发帖数: 45
7
en. u mean the subquery must return one row only. sigh... the sql server
syntax makes more sense, wonder what oracle is thinking ...

【在 r***e 的大作中提到】
: Acturally, I tried this before, it only works when you have unique a2 values.
k****h
发帖数: 27
8
try this explicit cursor in loop:
/
BEGIN
FOR B in (select * from B)
LOOP
BEGIN
UPDATE A
set A.a2=(B.b2)
where A.a1=B.B1
END;
END LOOP;
END;
/

values.

【在 s******n 的大作中提到】
: en. u mean the subquery must return one row only. sigh... the sql server
: syntax makes more sense, wonder what oracle is thinking ...

1 (共1页)
进入Database版参与讨论
相关主题
请问那种很复杂的sql语句,有什么套路吗?求教(SQL/Access): Join两个query tables 出错
cursor可以往回找否??请教一个SQL query该怎么写
问个数据库问题包子请教query
Re: recursive sql?NOT= , NOT IN 有啥区别
有关oracle form的新手问题SQL Query Question
老印给我的一个Challenge怎么reference temp table的column
其实我发现了CODE的写得好不好关于学习数据库我也说几句
Re: Recordset - I stuck! Help!correlated subquery
相关话题的讨论汇总
话题: query话题: update话题: end话题: loop话题: make