EDIT
以下代码提供了PRDTQUESTION表中的特定记录。基于这些分离的记录,我试图使用列FROM_PRODUCTFRAMESEQNO中的值(将值从FROM_PRODUCTFRAMESEQNO复制到TO_PRODUCTFRAMESEQNO)来更新TO_PRODUCTFRAMESEQNO列中的值。
我对SQL还是很陌生,我不确定我的方法是否正确。你们可以看看吗?谢谢你的帮助。
select p.PRDTQUESTIONSEQNO AS FROM_PRDTQUESTION,
p.PRODUCTFRAMESEQNO AS FROM_PRODUCTFRAMESEQNO,
v.PRDTQUESTIONSEQNO AS TO_PRDTQUESTION,
V.PRODUCTFRAMESEQNO AS TO_PRODUCTFRAMESEQNO
FROM prdtquestion p
JOIN PRDTQUESTION v
ON p.parttypeseqno = v.parttypeseqno
where p.questionseqno in (4958) and p.parttypeseqno
in (select parttypeseqno from parttypeversummary where mqparttypeverseqno = 99464)
AND v.PRDTQUESTIONseqno in
(select PRDTQUESTIONseqno from prdtquestion where questionseqno in (31138)
and parttypeseqno in (select parttypeseqno from parttypeversummary where mqparttypeverseqno = 99464));
上面脚本的输出-SEGREGATED TABLE -几乎所有行中的FROM_PRODUCTFRAMESEQNO和TO_PRODUCTFRAMESEQNO列中的值都不同
FROM_PRDTQUESTION FROM_PRODUCTFRAMESEQNO TO_PRDTQUESTION TO_PRODUCTFRAMESEQNO
999228 14193 999051 14189
999229 14169 998957 14169
999230 14177 998983 14173
999231 14121 999068 14117
999232 14145 998941 14141
999233 14137 998924 14133
999234 14185 998907 14181
999235 18862 999161 18859
999236 18870 999178 18867
999237 18878 999195 18875
999238 17943 999110 17940
预期结果: -如您所见,FROM_PRODUCTFRAMESEQNO和TO_PRODUCTFRAMESEQNO列中的值相同
FROM_PRDTQUESTION FROM_PRODUCTFRAMESEQNO TO_PRDTQUESTION TO_PRODUCTFRAMESEQNO
999228 14193 999051 14193
999229 14169 998957 14169
999230 14177 998983 14177
999231 14121 999068 14121
999232 14145 998941 14145
999233 14137 998924 14137
999234 14185 998907 14185
999235 18862 999161 18862
999236 18870 999178 18870
999237 18878 999195 18878
999238 17943 999110 17943
我尝试了更新,但没有成功:
update PRDTQUESTION
set TO_PRODUCTFRAMESEQNO = FROM_PRODUCTFRAMESEQNO, usid = 'ACKLIM01', tmstamp = SYSDATE
where PRDTQUESTION in (
select p.PRDTQUESTIONSEQNO AS FROM_PRDTQUESTION,
p.PRODUCTFRAMESEQNO AS FROM_PRODUCTFRAMESEQNO,
v.PRDTQUESTIONSEQNO AS TO_PRDTQUESTION,
V.PRODUCTFRAMESEQNO AS TO_PRODUCTFRAMESEQNO
FROM PRDTQUESTION p
JOIN PRDTQUESTION v
ON p.parttypeseqno = v.parttypeseqno
where p.questionseqno in (4958) and p.parttypeseqno
in (select parttypeseqno from parttypeversummary where mqparttypeverseqno = 99464)
AND v.PRDTQUESTIONseqno in
(select PRDTQUESTIONSEQNO from PRDTQUESTION where questionseqno in (31138)
and parttypeseqno in (select parttypeseqno from parttypeversummary where mqparttypeverseqno = 99464))
);
对于PRDTQUESTION表中的单个更新,对我有用的是
“单个更新脚本”
update prdtquestion
set PRODUCTFRAMESEQNO = (select PRODUCTFRAMESEQNO from prdtquestion where prdtquestionseqno in (999229)), tmstamp = SYSDATE, usid = 'ACKLIM01'
where prdtquestionseqno = 998957;
脚本中的值:'(999229)中的prdtquestionseqno'和'prdtquestionseqno = 998957'取自'SEGREGATED TABLE'。
我可以重复执行“单次更新脚本”以分别更新“ SEGREGATED TABLE”中的每个单元格-但我正在寻找一些捷径
让我知道一切仍然不清楚。 谢谢
答案 0 :(得分:0)
据我了解,以下查询可能会对您有所帮助。
select * from (select p.PRDTQUESTIONSEQNO AS FROM_PRDTQUESTION,
p.PRODUCTFRAMESEQNO AS FROM_PRODUCTFRAMESEQNO,
v.PRDTQUESTIONSEQNO AS TO_PRDTQUESTION,
V.PRODUCTFRAMESEQNO AS TO_PRODUCTFRAMESEQNO
FROM prdtquestion p
JOIN PRDTQUESTION v
ON p.parttypeseqno = v.parttypeseqno
where p.questionseqno in (4958) and p.parttypeseqno
in (select parttypeseqno from parttypeversummary where mqparttypeverseqno = 99464)
AND v.PRDTQUESTIONseqno in
(select PRDTQUESTIONseqno from prdtquestion where questionseqno in (31138)
and parttypeseqno in (select parttypeseqno from parttypeversummary where mqparttypeverseqno = 99464)))A where A.FROM_PRODUCTFRAMESEQNO=A.TO_PRODUCTFRAMESEQNO ;
如果您希望将FROM_PRODUCTFRAMESEQNO的每个值与所有TO_PRODUCTFRAMESEQNO值进行匹配,无论它属于哪一行,那么都可以使用exist / in运算符。
答案 1 :(得分:0)
这应该有效并且更简单。为了简单起见,我已经修剪了SQL。
select *
from (
select p.PRDTQUESTIONSEQNO AS FROM_PRDTQUESTION,
p.PRODUCTFRAMESEQNO AS FROM_PRODUCTFRAMESEQNO,
v.PRDTQUESTIONSEQNO AS TO_PRDTQUESTION,
V.PRODUCTFRAMESEQNO AS TO_PRODUCTFRAMESEQNO
FROM prdtquestion p
JOIN PRDTQUESTION v
ON p.parttypeseqno = v.parttypeseqno
) where FROM_PRDTQUESTION <> TO_PRDTQUESTION