2014-02-26 13 views
0

由於我使用的報告軟件,我必須將所有內容放在一個報表的sql語句中。但是,即使Oracle最終產品中只有1個結果,Oracle SQL似乎也不會讓我創建具有單組結果的內部選擇。 (所有其他結果都是單組功能)。 這裏是我的SQL:內部選擇語句不註冊爲單組功能...「不是單一組功能」

select 
COUNT(*) as TOTAL_RXS, 
SUM(rx_tx.brand_acquisition_cost) as TOTAL_COST, 
SUM(case rx_tx.drug_dispensed 
    when 'B' then (rx_tx.brand_price - rx_tx.brand_discount) 
when 'G' then (rx_tx.generic_price - rx_tx.generic_discount) 
end) 
    as TOTAL_PRICE, 
SUM(case rx_tx.drug_dispensed 
    when 'B' then (rx_tx.brand_price - rx_tx.brand_discount - rx_tx.brand_acquisition_cost) 
when 'G' then (rx_tx.generic_price - rx_tx.generic_discount - rx_tx.brand_acquisition_cost) 
end) 
as TOTAL_PROFIT 

    , (select 
    SUM(tx_tp.balance_due_from_tp) 
     from eps2.tx_tp 
    join eps2.rx_tx on rx_tx.id = tx_tp.rx_tx_id 
     where 1=1 
-- This results in CLAIM STATUS being 'F' 
    AND rx_tx.fill_date is not NULL 
    AND rx_tx.returned_date is not NULL 
    AND rx_tx.reportable_sales_date is NULL 
    AND (tx_tp.paid_status like '%PAID%' 
    OR tx_tp.paid_status like '%PART%')) as TOTAL_RECEIVABLES 

from eps2.vw_rx_summary join eps2.rx_tx 
    on vw_rx_summary.last_filled_rx_tx_id = rx_tx.id 
-- where TRUNC(rx_tx.fill_date,'DD') = TRUNC(SYSDATE - 1,'DD') 

誰能幫助我? 在此先感謝。

+0

您的查詢缺少外部查詢的'from'語句。如果這不是完整的查詢,那麼請顯示完整的查詢。 –

+0

對不起......我通過不包括查詢的某些部分來添加簡單性和保護公司sql代碼資產。但這是完整的查詢。謝謝。 –

+0

我想稱之爲「掩蔽」或類型轉換似乎不適用於我。這是說「異常:java.sql.SQLException:ORA-00936:缺少表達式」 –

回答

1
select COUNT(*) as TOTAL_RXS, 
    SUM(rx_tx.brand_acquisition_cost) as TOTAL_COST, 
    MAX(select 
     SUM(tx_tp.balance_due_from_tp) as total_receivables 
     from eps2.tx_tp 
     join eps2.rx_tx on rx_tx.id = tx_tp.rx_tx_id 
     where 1=1 
     AND (tx_tp.paid_status like '%PAID%' 
     OR tx_tp.paid_status like '%PART%')) as total_receivables 

添加MAX()total_receivables掩蓋它作爲一個聚集功能!