简体   繁体   English

Update语句中的“单行子查询返回多个行”

[英]“Single-row subquery returns more than one row” in Update statement

I've been struggling for a couple of days to work out how to make my update statement work. 我已经努力了几天,以研究如何使我的update语句正常工作。 The select statement appears to work as expected, but when I try to update my column values I get an ORA-01427 single-row subquery returns more than one row error. select语句似乎按预期工作,但是当我尝试更新列值时,出现ORA-01427 single-row subquery returns more than one row错误。

Here's the code: 这是代码:

UPDATE tbl_metrics
SET act_end_time = (WITH base
AS (SELECT caseid, entry_timestamp
       FROM activity
      WHERE act_id IN (100, 700, 300)
      )  
SELECT t1.entry_timestamp
FROM base t1, tbl_metrics t2
WHERE t1.caseid = t2.caseid
AND t2.act_start_time < (SELECT MIN(t1.entry_timestamp) FROM base t1 WHERE t1.caseid = t2.caseid))

The idea is that the tbl_metrics.act_end_time column is updated with the lowest entry_timestamp value from activity table where activity.caseid=tbl_metrics.caseid and activity.entry_timestamp>tbl_metrics.act_start_time and the activity.act_id is 100, 700, or 300. 这个想法是用activity表中的最低entry_timestamp值更新tbl_metrics.act_end_time列,其中activity.caseid=tbl_metrics.caseidactivity.entry_timestamp>tbl_metrics.act_start_timeactivity.act_idactivity.entry_timestamp>tbl_metrics.act_start_time或300。

I think it should be like this: 我认为应该是这样的:

UPDATE tbl_metrics t2
SET act_end_time = 
    (SELECT MIN(t1.entry_timestamp) 
    FROM activity t1 
    WHERE act_id IN (100, 700, 300)
        AND t1.entry_timestamp > t2.act_start_time
        AND t1.caseid = t2.caseid)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM