2012-10-19 3 views
1

제 질문과 유사한 많은 질문을 검색했지만 찾지 못했습니다. 이것은 오라클에서, 나는 버전을 모른다 (SQL Developer를 통해서만 접근한다). 결과 곳 t_user_promotion_points에서 합 (양)와update oracle에서 select 결과를 사용하십시오.

select user_id, promotion_id, sum(amount) from t_points_receipt 
where promotion_id = 10340 group by user_id, promotion_id; 

내가 뭘하고 싶은 것은 업데이트 t_user_promotion_points :이 쿼리를 가지고,

describe t_points_receipt 
Name    Null  Type   
----------------- -------- ------------- 
USER_ID   NOT NULL NUMBER(9)  
PROMOTION_ID  NOT NULL NUMBER(9)  
AMOUNT   NOT NULL NUMBER(9,2) 

describe t_user_promotion_points 
Name   Null  Type   
------------ -------- ----------- 
USER_ID  NOT NULL NUMBER(9) 
PROMOTION_ID NOT NULL NUMBER(9) 
TOTAL_POINTS   NUMBER(9,2) 

을 그리고 : 나는 두 테이블 (생략 관련성이없는 열)이 .user_id = (결과) .user_id 및 t_user_promotion_points.promotion_id = (결과) .promotion_id. 이것을 할 수있는 방법이 있습니까?

답변

1

당신은 설정 값에 상관 하위 쿼리를 만들 수 있습니다

update t_user_promotion_points p 
set total_points = (select sum(amount) from t_points_receipt r where p.user_id = r.user_id and p.promotion_id = r.promotion_id) 
where p.promotion_id = 10340; 
+0

그게 효과가! 매우 감사합니다. – user1547208

2
update t_user_promotion_points p 
set total_points = select sum(amount) from t_points_receipt r 
on p.user_id = r.user_id 
where r.promotion_id = 10340 and 
where t.promotion_id = 10340 
+0

초 : 빠른 응답 – RThomas

+0

감사에 의해 나를 이길! ' 오류는 명령 라인 1에서 시작 :하지만,이 오류가 업데이트는 t_points_receipt이 p.user_id에 는 = 을 r.user_id 곳 r.promotion_id = 10340 r에에서 P 설정 total_points = 선택 합 (양) t_user_promotion_points 및 경우 명령 줄에서 t.promotion_id = 10340 오류 :이 칼럼 : 19 오류 보고서 : SQL 오류 : ORA-00936 :없는 표현 00936. 00000 - "실종 표현" * 원인 : * 작업 : ' – user1547208

+0

위 서식을 작성해 주셔서 죄송합니다. 문제를 해결하려고했지만 시간이 초과되었습니다. – user1547208

관련 문제