我正在尝试更新oracle表中的字段,但是我只想根据创建日期字段升序的顺序来更新75行。
这是我到目前为止的内容,但是没有用。
UPDATE extractcandidate
SET process = 15
WHERE process IN
(Select process from extractcandidate where process = 1500 and rownum <=75 order by creationdate);
答案 0 :(得分:1)
如@Gordon所述,您需要在ORDER BY
之前做ROWNUM
。
首先,按creationdate
排序:
SELECT *
FROM extractcandidate
WHERE process=1500
ORDER BY creationdate;
第二,将数字限制为75:
SELECT *
FROM (
SELECT *
FROM extractcandidate
WHERE process=1500
ORDER BY creationdate
)
WHERE rownum <= 75;
现在,您可以将其输入UPDATE
中。为了找到正确的行,通常会使用主键列。您的情况似乎不存在,因此您可以使用Oracle内部的ROWID
:
UPDATE extractcandidate
SET process=15
WHERE rowid IN (
SELECT ri
FROM (
SELECT rowid as ri
FROM extractcandidate
WHERE process=1500
ORDER BY creationdate
)
WHERE rownum <= 75
);
答案 1 :(得分:0)
您需要其他子查询才能使方法起作用:
UPDATE extractcandidate
SET process = 15
WHERE ec.process = 1500 AND
creationdate IN (SELECT ec.creationdate
FROM (SELECT ec.*
FROM extractcandidate ec
WHERE ec.process = 1500
ORDER BY ec.creationdate
)
WHERE rownum <= 75
);
注意:
rownum
。process
。