2012-09-04 3 views
0
select product.id,product.name,product.itemcode,sum(product.amount)as total_amount 
from product where product.account in 
select G.account from report_results G 
where  G.status='Y') 
group by product.id,product.name,product.itemcode 

은 (내가 proc_temp 위오라클 쿼리 발견 문제

(select product.id,product.name,product.itemcode,sum(product.amount)as total_amount 
    from product where product.account in 
    (select G.account from report_results G 
    where  G.status='Y'))as Input,proc_temp 
    where Input.id=proc_temp.id 

라는 새 테이블을 사용하고 난 아래와 같이 QUERY1 수정 작업을 수행하기 위해 지금 QUERY1

로 위의 고려 쿼리가 올바르게 형성되지 않았습니다. 나는 새로운 테이블 proc_temp 으로 query1에 가입하고 그 id 컬럼을 비교하려고합니다.이 구문을 수정하는 데 도움이 되길 바랍니다.

+0

주십시오 샘플 데이터를 원하는 출력 있다고 가정합니다. – RedFilter

답변

1

SELECT 절을 추가하십시오. 난 당신이 뭘 원하는지 알 수 없기 때문에 나는이 쿼리에 대한 신뢰도를 보장 할 수 없습니다,하지만 뭔가 같은 :

select i.* 
from (
    select product.id, product.name, product.itemcode, sum(product.amount) as total_amount 
    from product 
    where product.account in (
      select G.account 
      from report_results G 
      where G.status = 'Y' 
      ) 
) i 
inner join proc_temp t on i.id = t.id 
+0

'i.id'는 어디에서 왔습니까? – paul

+0

@ 폴'i.id'가 파생 테이블 immmediately 후 첫'from' 키워드 – RedFilter

+0

네에서 온다 - 그 – paul

1

나는 부질 제거 것이고, 내부 조인 사용합니다. 게다가 다음 쿼리는 Input.id가 G.account

select p.id,p.name,p.itemcode,sum(p.amount)as total_amount 
from product p 
inner join report_results g on (p.account = g.account) 
inner join proc_temp pt on (g.account = pt.id) 
where g.status='Y' 
group by product.id,product.name,product.itemcode 
+0

@ Carlos.T 응답을 감사드립니다. – user472625