2016-03-21 15 views
0

Ich möchte TOTAL_DURATION von dem Wert in Spalte aktualisieren Tabelle IAM_RSP_INSTRUCTION, wobei der Wert von TOTAL_DURATION auf der Abfrage basiertUpdate-Spalte mit Daten aus mehreren Tabellen

select (paid_rsp + rd) as total from 
(
    select count (b.rsp_instruction_id) as paid_rsp, a.rsp_duration as rd, 
    b.rsp_instruction_id 
    from IAM_RSP_INSTRUCTION a 
    JOIN IAM_BUY_FUND_INFO b on a.RSP_ID = b.RSP_INSTRUCTION_ID 
    where b.RSP_INSTRUCTION_ID is not null 
    and a.rsp_status= 'approved' or a.rsp_status='terminated' 
    group by a.rsp_duration, b.rsp_instruction_id, a.rsp_status<br> 
    HAVING a.rsp_duration > -1 
    order by b.rsp_instruction_id 
) , 
and rsp_id from IAM_RSP_INSTRUCTION = rsp_instruction_id 
from IAM_BUY_FUND_INFO 

Derzeit habe ich eine Aktualisierungsabfrage:

UPDATE IAM_RSP_INSTRUCTION 
SET j.TOTAL_DURATION = (
    select (paid_rsp + rd) as total 
    from (
    select count (b.rsp_instruction_id) as paid_rsp, a.rsp_duration as rd, 
     b.rsp_instruction_id 
    from iam_rsp_instruction a 
    JOIN iam_buy_fund_info b on a.RSP_ID = b.RSP_INSTRUCTION_ID 
    where b.RSP_INSTRUCTION_ID is not null 
    and a.rsp_status= 'approved' or a.rsp_status='terminated' 
    group by a.rsp_duration, b.rsp_instruction_id, a.rsp_status 
    HAVING a.rsp_duration > -1 
    order by b.rsp_instruction_id 
) 
    WHERE IAM_RSP_INSTRUCTION.rsp_id = rsp_instruction_id 
); 

Wenn ich die Abfrage nach 8 Stunden ausführen, läuft es noch und keine Datensätze aktualisiert werden.

Hinweis: Die Unterabfrage hat funktioniert, als ich sie ausgeführt habe.

select (paid_rsp + rd) as total from 
    (
     select count (b.rsp_instruction_id) as paid_rsp, a.rsp_duration as rd, 
     b.rsp_instruction_id 
     from IAM_RSP_INSTRUCTION a 
     JOIN IAM_BUY_FUND_INFO b on a.RSP_ID = b.RSP_INSTRUCTION_ID 
     where b.RSP_INSTRUCTION_ID is not null 
     and a.rsp_status= 'approved' or a.rsp_status='terminated' 
     group by a.rsp_duration, b.rsp_instruction_id, a.rsp_status<br> 
     HAVING a.rsp_duration > -1 
     order by b.rsp_instruction_id 
    ) 

Bitte helfen. Vielen Dank.

+2

Welche DBMS verwenden Sie? sql srver <> oracle. Und Sie müssen "nicht funktionieren" definieren. –

+0

Bitte senden Sie die Fehlermeldung. –

+0

Lassen Sie Ihre Anfrage zuerst bearbeiten und dann herausfinden, wie Sie sie im Update verwenden. Sie müssen die Daten aus der Tabelle, die Sie aktualisieren, mit der von Ihnen verwendeten Unterabfrage korrelieren. –

Antwort

0

Hier ist eine Aufnahme mit dem Fix für die sichtbarsten Probleme, die ich finden kann. Wenn Sie eine Tabellenstruktur und einige Beispiele bereitstellen, könnte dies getestet werden.

UPDATE IAM_RSP_INSTRUCTION j 
    SET j.TOTAL_DURATION = (select (paid_rsp + rd) as total 
          from (select count (b.rsp_instruction_id) as paid_rsp, 
              a.rsp_duration as rd, 
              b.rsp_instruction_id 
            from iam_rsp_instruction a 
              JOIN 
              iam_buy_fund_info b 
              on a.RSP_ID = b.RSP_INSTRUCTION_ID 
            where b.RSP_INSTRUCTION_ID is not null 
             and (a.rsp_status= 'approved' 
             or a.rsp_status='terminated') 
             and b.rsp_instruction_id = j.rsp_id 
           group by a.rsp_duration, 
              b.rsp_instruction_id, 
              a.rsp_status 
            HAVING a.rsp_duration > -1)); 
Verwandte Themen