2012-09-04 46 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 

考慮以上爲QUERY1Oracle查詢發現問題

現在爲了執行操作我修改了QUERY1如下(我使用了一個名爲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 

上述新表查詢的格式不正確。我想用一個新表proc_temp 加入查詢1,並比較它的兩個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

@paul'i.id'在第一個'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.Thanks迴應 – user472625